-
I would like to use the pgp insert helper to generate an insert query. However, I neet to generate an id using a sequence generator. How would I tell this to pgp helper? The "handmade" query would look like insert into border(id, timestamp, sensor_device_id, value) VALUES(nextVal('sequence_border'), '2023-04-17T08:19:00.000Z', 'ABCDE', 0) How can i achive that with the insert helper function? const borderCrossingColumns = new pgp.helpers.ColumnSet(['id', 'timestamp', 'sensor_device_id', 'value'],
{table: 'border_crossing'});
const query = pgp.helpers.insert(bordersArray, borderCrossingColumns) |
Beta Was this translation helpful? Give feedback.
Answered by
vitaly-t
Apr 17, 2023
Replies: 1 comment 1 reply
-
Your {
name: 'id',
mod: ':raw',
init: () => pgp.as.format('nextVal($1)', ['sequence_border'])
} Or even simpler, if the column text is static: {
name: 'id',
mod: ':raw',
init: () => 'nextVal(\'sequence_border\')'
} See Column class. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
if-mar
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your
id
column should be:Or even simpler, if the column text is static:
See Column class.