0

The docs for INSERT INTO on Postgres 12 describe the command like this:

INSERT INTO table_name [ AS alias ] [ ( column_name [, ...] ) ]
    [ OVERRIDING { SYSTEM | USER } VALUE ]
    { DEFAULT VALUES | VALUES ( { expression | DEFAULT } [, ...] ) [, ...] | query }
    [ ON CONFLICT [ conflict_target ] conflict_action ]
    [ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ]

where conflict_target can be one of:

    ( { index_column_name | ( index_expression ) } [ COLLATE collation ] [ opclass ] [, ...] ) [ WHERE index_predicate ]
    ON CONSTRAINT constraint_name

If I'm reading that right, it means that you can specify index_column_name without brackets like this:

INSERT TO
...
ON CONFLICT my_column
DO NOTHING

But in fact I get:

ERROR:  syntax error at or near "my_column"
LINE 19: ON CONFLICT my_column

Have I read the documentation wrong?

I'm using Postgres 12.11.

1
  • 1
    You missed the fact that parentheses must be around the column name(s) (my_column)
    – user1822
    Oct 4, 2022 at 11:57

1 Answer 1

3

I found that part of the page to be a bit confusing, but I guess the "(" in:

( { index_column_name |

must be present. There are several examples on the page which all uses parantheses around the value:

INSERT INTO distributors (did, dname)
VALUES (5, 'Gizmo Transglobal'), (6, 'Associated Computing, Inc')
    ON CONFLICT (did) DO UPDATE SET dname = EXCLUDED.dname;
2
  • 1
    The syntax of the syntax diagrams is documented here: All other symbols, including parentheses, should be taken literally Oct 4, 2022 at 13:18
  • Drat, I thought that parenthesis was a group of things, but the group is { a | b | c }. Thanks everyone.
    – LondonRob
    Oct 4, 2022 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.