I'm trying to use Dapper, Npgsql to connect to a postgres database from a .net application. After an insert, I want to know the id of inserted row. I have read and tried options discussed here.
I have tried using returning id
like so:
id = connection.Execute("insert into document_tag (tag) values (@tag) returning id;",
new { tag },
transaction);
but I get only '1' in id.
I also tried to use currval
like so:
id = connection.Execute("insert into document_tag (tag) values (@tag); select currval(pg_get_serial_sequence('document_tag','id'));",
new { tag },
transaction);
Even in this case, I get only '1' in id
.
In both cases, the insert was successful and the id column in the database had a valid serial number other than '1'.
Is my expectation wrong or is there an alternative?