porsager / postgres

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

Unable to parse Default Var on ALTER TABLE #821

Open Bloodiko opened 7 months ago

Bloodiko commented 7 months ago

I tried writing a transform script with this library for my table as I require it to have a new value.

So i used

sql`ALTER TABLE rewrite ALTER COLUMN token SET DEFAULT ${variable};`;

I tried this query in multiple different ways. I tried setting the Default directly while ADD COLUMN.

None worked. The Result was always Postgres Error 42P18 - Query became ALTER TABLE rewrite ALTER COLUMN token SET DEFAULT $1;

Even though i actually did use the variable without quotes, which usually produce this error. Also, I did use the same variable in 2 other queries before, which did work as intended.

Not sure why ALTER TABLE does not like the DEFAULT setting here. ?

Why is $1 not transformed to the correct value for the given sql Query above ?