I want to use the mod function in PostgreSQL. Honeysql generates the following:
dev> (honey.sql/format {:select [[[:mod 2024 100]]]})
["SELECT ? MOD ?" 2024 100]
But apparently it's not valid in PostgreSQL:
db=> select (2024 mod 10);
ERROR: syntax error at or near "mod"
LINE 1: select (2024 mod 10);Huh. MOD has been registered as an infix operator in the very first commit.
But it's a function in PostgreSQL, SQL Server, SQLite, Oracle, MySQL, H2, MariaDB,...
As a kind of a local hotfix you can (swap! @#'honey.sql/infix-ops disj :mod).
As an alternative, use the % operator instead of the mod function. Should be the same thing.
Great, I will use % then. Thanks!
When I rewrote it for version 2.x, I copied the basic list from 1.x: https://github.com/seancorfield/honeysql/blob/v1/src/honeysql/format.cljc#L120-L123 which, as Eugene says, has had mod since the very first commit 12 years ago... and @bingen.galartza is the first person to try [:mod ..] and discover it's not valid SQL syntax! 🤯