Greetings.

I'm doing a script that inserts a record on a table and then, if there are some checkboxes marked, insert a bunch of other records in another table, using the id inserted in the first one.

I'm doing this in a very dangerous way, 'cause I'm doing this by:

1) I get the nextval of a sequence
2) I use this value to make all insertions

Another approach would be making a select on unique fields after the first insertion, so I can find out the inserted ID, but it's a pretty nasty way of doing it... :rolleyes:

I was wondering if there's a clever way of doing this. I know there's a function for doing this on mySQL, but couldn't found any similar function for PostgreSQL...

Any ideas?

TIA,

    You could perhaps use the inserted row's OID; see [man]pg_last_oid[/man] for details, and have a look at the user notes as well.

      Write a Reply...