porsager / postgres

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

Greedy "select" builder? #774

Open dvv opened 6 months ago

dvv commented 6 months ago

Given

const data = { name: "foo" }

The following

with cf as (insert into app.custom_field as cf ${sql(data)} returning cf) ...

is translated to

with cf as (insert into app.custom_field as cf $1 as \"name\" returning cf) ...

while I expect vanilla insert-like expansion like

with cf as (insert into app.custom_field as cf (name)values($1) returning cf) ...

Traces led to as cf token forces the statement to be treated as "select" builder, not "insert" one.

Please consider fixing or pointing out how to gracefully work this around.