Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgreSQL : ON CONFLICT 구문과 Sequence 함께 사용하기 #102

Open
nhkiiim opened this issue Feb 21, 2023 · 1 comment
Open

PostgreSQL : ON CONFLICT 구문과 Sequence 함께 사용하기 #102

nhkiiim opened this issue Feb 21, 2023 · 1 comment

Comments

@nhkiiim
Copy link
Owner

nhkiiim commented Feb 21, 2023

PostgreSQL에서 ON CONFLICT 구문 사용 시 시퀀스를 함께 사용하면 conflict 조건을 확인을 위해 시퀀스 값을 입력하게 되고,
자동으로 시퀀스를 생성해주는 INSERT인 경우 NULL 값이 들어가며 NOT NULL 제약조건을 위반

INSERT INTO 테이블 (  TEST_ID, TEST_NM  ) VALUES 
( 5, 'name' ) ON CONFLICT ( TEST_ID ),
( NULL, 'name' ) ON CONFLICT ( TEST_ID )
DO UPDATE SET 
TEST_NM = 'name'

PostgreSQL SERIAL : #101

스택오버플로 관련 이슈

@nhkiiim
Copy link
Owner Author

nhkiiim commented Feb 21, 2023

MyBatis 조건문을 사용해 동적 쿼리로 UPDATE가 아닐 때(NULL이 아닐 때)만 시퀀스 INSERT 명시적으로 표기..
더 좋은 방법이 있을 것 같음..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant