porsager / postgres

Postgres.js - The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare
The Unlicense
7.26k stars 262 forks source link

Dynamic values example does not work and appears syntactically incorrect. #716

Open cmdruid opened 10 months ago

cmdruid commented 10 months ago

Hello. Forgive my naivety please. I have been trying to figure out the API for the dynamic query for several hours.

In your docs you have the following example:

const [{ a, b, c }] => await sql`
  select
    *
  from (values ${ sql(['a', 'b', 'c']) }) as x(a, b, c)
`

This example appears incorrect to my code editor because the input arguments are not defined. I assume that the array ['a', 'b', 'c'] is supposed to instead be [a, b, c] as the input, however this does not work either. I keep getting the error PostgresError: there is no parameter $1.

I have tried looking at other issues and seeing how other people are doing it, however I can't get a basic example of this working, so I am at a loss of what to do.

Any help would be appreciated, thank you!

cmdruid commented 10 months ago

it turns out that this query fails with error when using .describe(), but runs correctly when executed (replacing ['a', 'b', 'c'] with [a, b, c]).

I am even more confused why the example works when executed (with the fixed syntax) but fails when being inspected with .describe(). I would like some clarification on what I am doing wrong so that I may do better in the future, thank you.