pgtyped icon indicating copy to clipboard operation
pgtyped copied to clipboard

Dynamic queries don't work

Open red1ng opened this issue 5 years ago • 4 comments

Maybe I'm some kind of special, but dynamic queries don't work for me ;(

Example from the documentation:

/* @name GetAllUsers */
SELECT * FROM users
ORDER BY (CASE WHEN :asc = true THEN :sort_column END) ASC, :sort_column DESC;

When I try to make queries everything runs without error, but sorting doesn't work

const users = await getAllUsers.run(
{
    asc: false,
    sort_column: 'id'
  },
  client
)

If you substitute id instead of :sort_column in the original query, then everything works

red1ng avatar Aug 19 '20 00:08 red1ng

I experiencing the same issue, is this being looked into?

deanvanniekerk avatar Nov 30 '20 18:11 deanvanniekerk

Same issue for me too.

jeremybastin1207 avatar Feb 06 '21 13:02 jeremybastin1207

It's unclear why this is even in the documentation. Looking at the tests it does not look like there are any to cover order by.

Also, it does not look like Postgres even supports this:

https://github.com/brianc/node-postgres/issues/300

You would have to do it using a shit load of case statements like so:

https://stackoverflow.com/a/48855828/4195244

andrew310 avatar Apr 14 '21 19:04 andrew310