Skip to content
Advertisement

How to use nextval() to insert a row containing its own ID in a string

I have a table that contains a column with a string containing its own ID. How can I insert a new line using a single SQL statement?

I need something like

https://www.db-fiddle.com/f/3NwLNBirN7mHKpDk9NyHSy/1

Advertisement

Answer

One option is to select the next serial in a subquery first:


You could also use a computed column instead would make for cleaner insert code:

Gives you:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement