porsager / postgres

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

dynamic column selection with column naming alias is not working #849

Closed benjamin79 closed 1 month ago

benjamin79 commented 2 months ago

Hi,

i have an array (columnsToSelect) of columns to which i want add another one

columnsToSelect.push("(firstname || ' ' || lastname) as fullname");

SELECT ${sql(columnsToSelect)} FROM ${sql(table)}

I tried different combinations with " and ' but without success.

error: missing FROM-clause entry for table

Is this possible?

thanks

porsager commented 1 month ago

You need to use fragments to create the as ? parts.

https://github.com/porsager/postgres?tab=readme-ov-file#building-queries