Fork me on GitHub
#sql
<
2019-08-01
>
xiongtx18:08:35

Wondering if anyone else is has run into this issue: w/ clojure.java.jdbc: This works fine against Oracle:

(jdbc/query conn ["SELECT TO_CHAR(TRUNC(\"date_col\"), 'yyyy-Mon-dd') AS \"value\" FROM \"MY_TABLE\" GROUP BY TO_CHAR(TRUNC(\"date_col\"), 'yyyy-Mon-dd')"])
This gives ORA-00979: not a GROUP BY expression:
(jdbc/query conn ["SELECT TO_CHAR(TRUNC(\"date_col\"), ?) AS \"value\" FROM \"MY_TABLE\" GROUP BY TO_CHAR(TRUNC(\"date_col\"), ?)" "'yyyy-Mon-dd'", "'yyyy-Mon-dd'"])

hiredman23:08:53

that is interesting, I don't think I've ever done that with mysql or postgres either, it wouldn't surprise be if you got an error for that other places as well

hiredman23:08:22

it is only valid if the select and group by have the same parameter passed in, and the database cannot know that when the query is submitted to make a prepared statement

seancorfield23:08:27

@xiongtx You should not have the single quotes inside those strings when they are parameters.

seancorfield23:08:52

'yyyy-Mon-dd' is a SQL string, "yyyy-Mon-dd" is a Clojure string.