I'm using pg-promise to build inserts and updates with the helpers.insert and helpers.update.
Update works as desired but I keep running into a similar problem to this question: pg-promise helpers : optionnal fields in insert and multiple-update
i.e. optional columns with postgresql defaults cause the helpers.insert to throw an error when the property doesn't exist on the input data. On updates this triggers the skip functionality and it's fine, but as the docs indicate skip doesn't work on insert so it errors.
const input = { yup: true };
const query = this.pgp.helpers.insert(
input,
new this.pgp.helpers.ColumnSet(
[
{ name: 'yup', skip: (col) => !col.exists },
{ name: 'nope', skip: (col) => !col.exists },
I'm wonder why skip doesn't work on insert? Is there an alternative I'm missing?
Using def seems a bit dicey as I want to make use of the postgresql defaults rather than override them.
I've hunted around the interwebs and even found @vitaly-t answering the same question in 2016 using the skip functionality which seems to have been subsequently removed from helpers.insert.
So I'm stuck. How do I get the same skip functionality working for inserts?