是否可以在 pg-promise 多行插入中使用 nextval 函数?我有一个数据库(很遗憾我无法更改),其中 id 必须通过客户端插入,如下所示:
INSERT INTO some_object (object_id, object_name)
VALUES (nextval('some_object_seq'), ${object_name})
RETURNING object_id;
这适用于一个插入。但现在我必须一次插入多行并尝试 pgp.helpers.insert:
const cs = pgp.helpers.ColumnSet(['object_id', 'object_name'], { table });
const query = pgp.helpers.insert(values, cs) + 'RETURNING object_id';
database.many(query).then(data => {
return data
}).catch(error => {
logger.error(error, query);
});
在这种情况下有没有办法使用 nextval('some_object_seq') ?遗憾的是,我无法更改表定义中 id 列的默认值。