I'm connecting to a PostgreSQL database and I want to know whether or not a uuid exists in a UUID-type column in some table. The parameter uuid is generated in another function. In clojure I try
(jdbc/db-do-prepared {:datasource datasource}
"SELECT exists (SELECT 1 FROM account WHERE guid=?::uuid)"
[uuid])
But it throws an exception:
BatchUpdateException Batch entry 0 SELECT exists (SELECT 1 FROM table WHERE guid='dbe8cda5-d37c-3446-9b9c-85e0344af3b1'::uuid) was aborted. Call getNextException to see the cause. org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError (AbstractJdbc2Statement.java:2781)
If I connect to the database and paste the generated SQL and execute it it works fine. I can also insert from clojure using the following code:
(jdbc/db-do-prepared {:datasource datasource}
"INSERT INTO table(guid) VALUES (?::uuid)"
[uuid])
Relevant dependencies from project.clj:
[org.clojure/java.jdbc "0.4.2"]
[org.postgresql/postgresql "9.4-1205-jdbc42"]
[hikari-cp "1.3.1"]