5

In Postgres documentation INSERT there is an example of ON CONFLICT use:

INSERT INTO distributors (did, dname) VALUES (7, 'Redline GmbH')
ON CONFLICT (did) DO NOTHING;

I try the same thing:

INSERT INTO name_map VALUES ('key_value', 'val1','val2') 
ON CONFLICT (key_column) DO NOTHING;

But get ERROR: syntax error at or near "ON".

What am I missing?

postgres --version
> 9.5.0
frankhond
  • 427
  • 4
  • 15
  • 3
    Are you actually _running_ PostgreSQL 9.5? You may have multiple versions installed. –  Jan 20 '16 at 08:55
  • 2
    Sounds as if you are not connected to a Postgres 9.5 server. Post the output of `select version()` –  Jan 20 '16 at 08:55
  • Is `key_column` indexed? – Makoto Jan 20 '16 at 08:56
  • 1
    You can double check that you are connected to a 9.5 server with `SELECT version()` – pozs Jan 20 '16 at 09:01
  • 1
    select version() shows in fact that the server running is 9.4.5. Apparently there is a problem when starting postgres. I'll edit the question. Thanks! – frankhond Jan 20 '16 at 09:01
  • See this question on how to do it in Postgres < 9.5: http://stackoverflow.com/questions/17267417/how-to-upsert-merge-insert-on-duplicate-update-in-postgresql – Innokenty Jul 20 '16 at 09:39

1 Answers1

12

As several people pointed out in the comments, it turns out the wrong version of postgres is running.

select version()

in psql revealed this.

There must be an old installation of 9.4.5 hiding somewhere in my system.

frankhond
  • 427
  • 4
  • 15