250x250
Notice
Recent Posts
Recent Comments
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- Spring Boot
- 설정
- Source
- 오픈소스
- oracle
- error
- jpa
- git
- SpringBoot
- JDBC
- JavaScript
- 문서
- Thymeleaf
- spring
- Exception
- Eclipse
- MSSQL
- Tomcat
- myBatis
- Docker
- maven
- AJAX
- Core Java
- MySQL
- Open Source
- ubuntu
- Python
- STS
- PostgreSQL
- IntelliJ
Archives
- Today
- Total
헤르메스 LIFE
[PostgreSQL] Trigger 관련 본문
728x90
PostgreSQL은 Trigger 에서 Function 이나 Procedure 를 Call 을 하는 구조로 되어 있는 것 같습니다.
drop trigger [트리거명] on [트리거 관련 테이블명] cascade;
create or replace trigger [트리거명]
--after insert or update on [트리거 관련 테이블명]
after update on [트리거 관련 테이블명]
for each row
execute function [트리거에서 call할 함수명]();
-- DROP FUNCTION public.[트리거에서 call되는 함수명]();
CREATE OR REPLACE FUNCTION [트리거에서 call되는 함수명]()
RETURNS trigger
LANGUAGE plpgsql
AS $function$
Begin
if old.user_nm != new.user_nm or old.mail_addr != new.mail_addr or old.tel_no != new.tel_no
then
/* ZZ_USER_M 테이블이 수정되기 후 History 를 남깁니다. */
INSERT INTO [백업테이블명] (user_id, user_nm, mail_addr, tel_no,
, reg_id, reg_dtm, upd_id, upd_dtm) values
(new.user_id, new.user_nm, new.mail_addr, new.tel_no
, new.reg_id, new.reg_dtm, new.upd_id, new.upd_dtm);
end if;
return null;
end;
$function$
;
참고
https://neon.tech/postgresql/postgresql-triggers
PostgreSQL Triggers
Show how to work with PostgreSQL triggers, which are the functions invoked automatically when an event occurs in the associated tables.
neon.tech
728x90
'Database' 카테고리의 다른 글
| [Tibero] Caused by: java.sql.SQLException: JDBC-12003:Unable to open a session. (0) | 2024.05.30 |
|---|---|
| [Tibero] Tibero 관련 쿼리 (0) | 2024.05.21 |
| [Tibero] java.sql.SQLException: JDBC-5072:Failure converting NUMBER to or from a native type. (0) | 2024.05.17 |
| [Oracle] Procedure 예제 (0) | 2024.05.14 |
| [MariaDB] MariaDB Tool - DBeaver (0) | 2024.05.05 |