On 5/16/19 7:52 AM, Winanjaya Amijoyo wrote:
yes you are right!.. the insert was swallowed
I tried below:
WITH s AS (
SELECT pid,area FROM test WHERE area = '11'
), i AS (
INSERT INTO test (area)
SELECT '11'
WHERE NOT EXISTS (SELECT 1 FROM s)
RETURNING pid
)
UPDATE test
SET last_update = CURRENT_TIMESTAMP
WHERE pid = (SELECT pid FROM s UNION SELECT pid FROM i) Or pid =
(SELECT pid FROM s Where area = '11')
RETURNING pid;
insert does not returning pid
This is good starting point for finding out more:
https://www.postgresql.org/docs/11/queries-with.html#QUERIES-WITH-MODIFYING
--
Adrian Klaver
adrian.klaver@xxxxxxxxxxx