2017년 1월 14일 토요일

postgresql update or insert

CREATE TABLE test2 (id integer primary key, b varchar(10), c varchar(10), dt timestamp with time zone);

UPDATE test2 SET dt=CURRENT_TIMESTAMP WHERE id=1;
INSERT INTO test2 (id, b, c, dt)
       SELECT 1,'xxx', 'xZ', CURRENT_TIMESTAMP
       WHERE NOT EXISTS (SELECT 1 FROM test2 WHERE id=1);

댓글 없음:

댓글 쓰기