Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameters from sqlfn inside fields alias are not correctly passed to JDBC #399

Open
arttuka opened this issue Nov 11, 2018 · 0 comments
Open

Comments

@arttuka
Copy link
Contributor

arttuka commented Nov 11, 2018

Expected behavior:

Parameters are correctly passed and select expression completes successfully when sqlfn is used inside a fields alias within with.

Current behavior:

Executing such an expression throws exception PSQLException No value specified for parameter 1. org.postgresql.core.v3.SimpleParameterList.checkAllParametersSet (SimpleParameterList.java:257)

Steps to reproduce

DB tables:

parent (id serial primary key, name varchar)
child (id serial primary key, parent int references parent(id), name varchar)

Korma entities:

(declare parent child)
(defentity parent
  (pk :id)
  (has-many child {:fk :parent}))
(defentity child
  (pk :id)
  (belongs-to parent {:fk :parent}))

Korma expression to execute:

(select child
  (fields [:name :child_name])
  (with parent
    (fields [(sqlfn :COALESCE :name "orphan") :parent_name])))

Generated SQL from this expression:

SELECT "child"."name" AS "child_name", COALESCE("parent"."name", ?) AS "parent_name" FROM "child" LEFT JOIN "parent" ON "parent"."id" = "child"."parent"

Notably, this works correctly:

(select child
  (fields [:name :child_name]
          [(sqlfn :COALESCE :parent.name "orphan") :parent_name])
  (with parent))

Environment

Clojure 1.9.0
Korma 0.4.3 (org.clojure/java.jdbc 0.6.1)
PostgreSQL 10.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant