I’m using PostgreSQL and I need to get the id of the last inserted row. my table has id field of SERIAL type . Does Xojo support the PostgreSQL INSERT with RETURNING clause?
If not - what is the Xojo recommended alternative out of CURRVAL() or LASTVAL() options?
Many thanks
Yes, use SqlSelect(“INSERT … RETURNING …”)
It works for PreparedStatemepts, not sure about another way
RETURNING works great. Use it all the time
And as Kirill said, you just use an SQLSelect instead of an Execute.
Many thanks for both answers - both have, together, answered my question.
SQLSelect is for “anything that returns a result / record set”
So if you call a stored procedure that returns a record set you run it with SQSelect
Could your write a sample code? Sqlselect and returned id? Tks
Prepared statement, adding a new record to a table and returning the id this record got in a recordset with field “ID”
INSERT INTO tbl_note
(note1, note2, obsolete, fk_modifiedby, ts_modified)
VALUES ($1, $2, FALSE, $3, now()) RETURNING ID
this might seem odd but I suspect you could by using sqlselect - which is used for sql that returns results
You indeed can! I’ve been using this for quite some time now