I'm uploading thousands of rows into my postgreSQL database and to do so I'm using the COPY FROM
statement to save processing time.
I didn't found any information about that on StackExchange so I'm asking now: is it possible to retrieve the primary keys (or other column value) generated from the COPY statement like we could do with the RETURNING col_name
statement of an INSERT
statement ?
It's not possible with COPY
.
Only an INSERT
with RETURNING id
can give you id-s.
The fastest next to COPY
approach would be a multi-row insert:
INSERT INTO table(col1, col2) VALUES (val1, val2), (val3, val4),... RETURNING id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With