I'd like to get this working, but Postgres doesn't like having the WHERE
clause in this type of insert.
INSERT INTO keys(name, value) VALUES
('blah', 'true')
WHERE NOT EXISTS (
SELECT 1 FROM keys WHERE name='blah'
);
In Postgres, there is a really nice way to do that:
INSERT INTO keys(name, value)
SELECT 'blah', 'true'
WHERE NOT EXISTS (
SELECT 1 FROM keys WHERE name='blah'
);
hope that helps.-
In Postgresql 9.5 you can now use on conflict do nothing
insert into KEYS (name, value) values (
'blah', 'true') on conflict (name) do nothing;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With