honeysql

nbardiuk 2023-08-03T17:27:40.282549Z

Is there a way to reference a quoted alias without :raw? I want to use quoted alias in ORDER BY clause

SELECT column_name AS "some-alias" FROM b ORDER BY "some-alias" ASC
I would like to avoid using :raw because the alias value comes from 3d party
(honey.sql/format {:select [[:column-name "some-alias"]]
                   :from :b
                   :order-by [[[:raw "\"some-alias\""]]]})
Quoting everything doesn't work because it doesn't convert kebab column names to underscores
(honey.sql/format {:select [[:column-name "some-alias"]]
                   :from :b
                   :order-by [:some-alias]}
                  {:quoted true})
SELECT "column-name" AS "some-alias" FROM "b" ORDER BY "some-alias" ASC
And quoted-snake corrupts dashes in aliases
(honey.sql/format {:select [[:column-name "some-alias"]]
                   :from :b
                   :order-by [:some-alias]}
                  {:quoted-snake true})
SELECT column_name AS "some_alias" FROM b ORDER BY some_alias ASC

p-himik 2023-08-03T17:32:42.127709Z

Oh, huh. There's stuff like :'x but apparently it works only when it's in a function-calling context.

👍 1
nbardiuk 2023-08-03T17:36:53.486509Z

thank you for the :'x didn't know it exists, it can cover some cases

seancorfield 2023-08-03T18:10:57.612279Z

@nbardiuk Feel free to create an issue on GitHub for me to look at. AS aliases have special treatment so maybe I'll need to add special syntax like [:alias "some-alias"] so you can get that treatment elsewhere...

👍 1
nbardiuk 2023-08-03T18:20:45.027299Z

https://github.com/seancorfield/honeysql/issues/497

p-himik 2023-08-03T18:21:43.542869Z

@seancorfield Wouldn't it make more sense to support :'x everywhere? A breaking change, I suppose, but maybe could be put behind an opt-in flag?

seancorfield 2023-08-03T18:34:06.864759Z

That's something I'll take a look at as part of this issue.

seancorfield 2023-08-03T18:34:45.601829Z

I think the behavior of :'x may already be context-dependent but I'd have to refresh my memory...