I want to insert a row if it doesn't exist, else return the existing row. The following works fine for new rows, but it returns nothing in case the row already exist.
INSERT INTO product (brand, type)
SELECT 'aa', 'bb'
WHERE
NOT EXISTS (
SELECT * FROM product WHERE brand='aa' AND type='bb'
)
RETURNING *
I know a similar question had been asked before here, but the proposed solution (as I show above) doesn't work for me. In other words, this is not a duplicate question.