WITH x AS (
INSERT INTO users(name, age)
SELECT 'john', 30
WHERE NOT EXISTS (
SELECT id FROM users WHERE name = 'john'
) u
RETURNING (CASE WHEN u.id > 0 THEN u.id ELSE id END)
)
SELECT * FROM x
如何始终返回id,如果id不存在,则插入它。另外,我需要将它放在CTE中。