Skip to content

Possible to use a subscript in a named parameter reference? #868

Answered by vitaly-t
kmm asked this question in Q&A
Discussion options

You must be logged in to vote

For nested variables, only simple-property interpolation is currently supported,

i.e. replace

report.ts[0]
report.ts[1]
report.ts[2]

with

report.ts.0
report.ts.1
report.ts.2

And there's a definitely better way to do it, via Custom Type Formatting...

const tstamp = (t) => ({
    toPostgres: ()=> pgp.as.format('to_timestamp($1)', t),
    rawType: true
});
const dataObj = { 
  report:{ 
    ts: [1677844801,1677844801,1677844801].map(tstamp)
  }
}

Then you can use just '... VALUES(${report.ts})', dataObj), no need to manually format the query.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@kmm
Comment options

Answer selected by kmm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants