0

I have created trigger function that will try to insert data into remote database table like this:

db_res := dblink_exec('dbname=test user=test password=test host=localhost port=5432', 'INSERT INTO test (table, action) VALUES (''table'',''action'')');

When this trigger launches, it throws me this error:

syntax error (at or near: ",")

Why this is happening? How simple comma can cause this error?

1 Answer 1

3

table is a reserved word in SQL, so using it as a column name will cause this syntax error. If the column is really called table, you have to refer to it using the quoted identifier "table".

In order to avoid problems like this, it is highly commendable to not name objects with reserved keywords. You can find a list of those keywords in appendix C of the documentation.

Sign up to request clarification or add additional context in comments.

2 Comments

Damn it! This Postgresql should be saying that this name is reserved instead of throwing obscure messages!
Well, there is nothing fundamentally wrong about using an SQL keyword in an SQL statement. Perhaps it would be possible to do better, but a reserved keyword in an impossible makes the parser get lost in the woods.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.