Probably a long shot, but is syntax like this supported without extending honeysql?
select
* EXCLUDE (col1, col2),
other.col1,
other.col2
from ...
I think the above is pretty specific to duckdb.Not specific, no.
(sql/format {:select [[:* {:exclude [:coll1 :coll2]}] :other.coll1 :other.coll2]})
=> ["SELECT * EXCLUDE (coll1, coll2), other.coll1, other.coll2"]Great, thanks! I'm just now exploring honeysql, sorry, haven't covered all of the documentation yet.
No problem. :) This is one of the things this channel is for.
That was added for XTDB -- I didn't realize it was DuckDB as well https://cljdoc.org/d/com.github.seancorfield/honeysql/2.7.1368/doc/getting-started/xtdb-support?q=%3Aexclude#select-variations
ClickHouse also supports it: https://clickhouse.com/docs/sql-reference/statements/select/except
Yes, DuckDB also has https://duckdb.org/docs/stable/sql/query_syntax/select but that doesn't seem as necessary once you have EXCLUDE.
@p-himik EXCEPT is different to EXCLUDE -- HoneySQL has supported EXCEPT and REPLACE since 2022:
user=> (sql/format {:select [[:* :except [:a :b :c]]] :from [:table]})
["SELECT * EXCEPT (a, b, c) FROM table"]
user=> (sql/format {:select [[:* :replace [[[:* :a [:inline 100]] :b] [[:inline 2] :c]]]] :from [:table]})
["SELECT * REPLACE (a * 100 AS b, 2 AS c) FROM table"]
user=> (sql/format {:select [[:* :except [:a :b] :replace [[[:inline 2] :c]]]] :from [:table]})
["SELECT * EXCEPT (a, b) REPLACE (2 AS c) FROM table"]Ah, I can't read.
I probably should have made :exclude follow the same syntax but I think maybe XTDB allows more complex stuff which is why I didn't?
The programmability of the EXCLUDE implementation (e.g. with update-in) seems a bit better.
In fact I can't help but think that a uniform syntax of: a vector where the second element is always an optional map (so even (h/select [:longname {:as :short}])) would make the syntax a bit more memorable.
Feel free to create a GH issue for future consideration...