Skip to content

calling a plpgsql function with a composite type array argument #420

Answered by porsager
massivefermion asked this question in Q&A
Discussion options

You must be logged in to vote

Yeah, there's no good way to serialize records (yet), but you were close with your last attempt.

This one should work for you ;)

sql`select create_person(array[${ users.map((u, i) => sql`${ i ? sql`,` : sql``}(${ u.username }, ${ u.age })`) }]::person[])`

It will result in a query like this, and pass the values as parameters:

select create_person(array[($1, $2), ($3, $4)]::person[])

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by massivefermion
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