Retrieve serial ID with Npgsql when inserting with ExecuteScalar

后端 未结 4 1336
醉酒成梦
醉酒成梦 2020-12-16 19:08

I\'m trying to insert a row into a PostgreSQL table with a serial primary key and I need to retrieve this column after it was inserted. I got something like this:

Th

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-16 19:49

    Is that thread safe?
    What if another insert happens between your insert and select? Why not use:

    INSERT INTO table (fieldnames) VALUES (values) RETURNING idcolumn?

提交回复
热议问题