If you can't solve the problem,i suggest you post the question in the Postgres forums.
Best regards,
Sam
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
3 Points
7 Posts
How to grab the first sql statement's id as foreign key in 2nd sql statement?
Sep 10, 2019 09:08 AM|Happy Bee|LINK
I am using Postgres db for C#.net
How do I grab the first sql statement autoincrement id (primary key) into the second statement as foreign key?
Contributor
3370 Points
1409 Posts
Re: How to grab the first sql statement's id as foreign key in 2nd sql statement?
Sep 11, 2019 06:36 AM|samwu|LINK
Hi Happy Bee,
I'm sorry I'm not familiar with Postgres db.
But through my search, you can refer to this link to get primary key : https://stackoverflow.com/a/20537829
then set the foreign key by this link: https://www.postgresql.org/docs/9.2/ddl-constraints.html
If you can't solve the problem,i suggest you post the question in the Postgres forums.
Best regards,
Sam
All-Star
48520 Points
18073 Posts
Re: How to grab the first sql statement's id as foreign key in 2nd sql statement?
Sep 11, 2019 07:40 AM|PatriceSc|LINK
Hi,
Don't know much about it but from the doc it is actually a sequence behind the scene and so you should be able to use https://www.postgresql.org/docs/current/functions-sequence.html (maybe nextval() once the insert is done) to retrieve the next value.
If you have no other answer a specialized forum for PostgreSQL could be better.