Your code initially looked completely fictitious, since nothing looks like connecting a SELECT to the next INSERT , so even if it works, you just generate an identifier and discard it. It looks like your scripting tool can automatically determine the results of SELECT column columns as variables that can be referenced in later queries; see "copy to another database" in the Scriptella tutorial . A quick look at this suggests that what you want to do may work, but for this you will need to use the nested blocks <query/> and <script/> .
The correct way to use the generated identifier sequence is one of:
INSERT INTO zoologia.especie VALUES( nextval('SQC_ESPECIE'), ?generoId, ?especie, ?subespecie, ?variedad, ?genero, true ); INSERT INTO zoologia.especie VALUES( DEFAULT, ?generoId, ?especie, ?subespecie, ?variedad, ?genero, true ); INSERT INTO zoologia.especie(generoId, especie, subespecie, variedad, genero, someothercol) VALUES( ?generoId, ?especie, ?subespecie, ?variedad, ?genero, true );
Your question initially was to reuse remote identifiers (i.e. dimensionless sequences), but it looks like you clarified it to remove this.
Update after editing + comment changed the meaning of the question:
If you are trying to use the generated single-line identifier in subsequent INSERT s, you must either:
Grab the identifier with INSERT ... RETURNING or by calling currval('the_id_sequence') after INSERT , save the identifier in a client variable in a scripting language and pass it to the next INSERT s; or
Use currval('the_id_sequence') in the VALUES list of subsequent inserts.
I have not even heard that Scriptella does not use it, so I can not help with the 1st option of using variables on the client side. I would be very surprised if he didn’t have a way to save SELECT or INSERT ... RETURNING results for future use. A very quick look suggests that this is done with the nested blocks <query/> and <script/> , but this is just a 30 second look at the tutorial.
The second option is simple. Say you just inserted:
INSERT INTO zoologia.genero VALUES( DEFAULT, ?familiaId, ?genero, true );
and want to insert a new line into especie that has the generoId just inserted. Assuming the ID sequence for genero follows the standard PostgreSQL names, tablename_columnname_id_seq , you should use:
INSERT INTO zoologia.especie VALUES( DEFAULT, currval('genero_generoId_seq'), ...);
Cm: