Picture of Wim 4127
Registered 6 years 310 days
Wim 4127 Wednesday, 3 June 2020, 05:06 PM
Why is my statement extended with "RETURNING id"?
When I execute the statement

_database->InsertSQL(this, "INSERT INTO sraps_config (name, value) VALUES (%s, %s) ON CONFLICT (name) DO UPDATE SET value=excluded.value", name.c_str(), value.c_str());

Then I see in the app logging output

06-03 14:56:16.574 Snom Provisioning@snom.com PostgreSQLDatabase(001002b8,0010016c)::ExecSQLV user:00100374 flags:00800001 sqlCmd:INSERT INTO sraps_config (name, value) VALUES ('apiKey', 'test1') ON CONFLICT (name) DO UPDATE SET value=excluded.value RETURNING id

Which of course leads to an error

06-03 14:56:16.578 Snom Provisioning@snom.com PostgreSQLDatabase(001002b8,0010016c)::LastCommandFailed (42703):ERROR: column "id" does not exist

and that makes sense since I have no id column either. My primary key in the table is the name column...
Picture of Daniel Deterding (innovaphone)
Moderator Registered 15 years 179 days
Daniel Deterding (innovaphone) Thursday, 4 June 2020, 08:04 AM
Re: Why is my statement extended with "RETURNING id"?
InsertSQL is specifically meant for tables with an id column.
If you take a look at the InsertSQLResult callback function, you'll notice that you get an ulong64 id back here, which is of course just possible if your table has an id column.

Just use ExecSQL in your case, as you can issue every query with ExecSQL as well.

Greetings,
Daniel
← You can define your color theme preference here