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

Cannot bind variables within on clause of query joins #1678

Closed
stavro opened this issue Sep 8, 2016 · 1 comment
Closed

Cannot bind variables within on clause of query joins #1678

stavro opened this issue Sep 8, 2016 · 1 comment

Comments

@stavro
Copy link
Contributor

stavro commented Sep 8, 2016

Environment

  • Elixir version: 1.3.0
  • Database and version: Postgres 9.5
  • Ecto version: 2.0.5
  • Database adapter and version: Postgrex v0.12
  • Operating system: OS X

Current behavior

Variables cannot be bound in the on clause of an Ecto.Query join:

one = 1

Repo.all(
  from u in User,
  left_join: staff in assoc(u, :staff), on: 1 == ^one,
  select: u.id
)

Error:

** (ArgumentError) parameters must be of length 1 for query %Postgrex.Query{columns: ["id"], copy_data: false, decoders: [#Function<8.109917431/1 in Postgrex.Types.decoder/2>], encoders: [#Function<9.109917431/1 in Postgrex.Types.encoder/2>], name: "ecto_31925", null: nil, param_formats: [:binary], param_info: [{23, %Postgrex.TypeInfo{array_elem: 0, base_type: 0, comp_elems: [], input: "int4in", oid: 23, output: "int4out", receive: "int4recv", send: "int4send", type: "int4"}, Postgrex.Extensions.Int4}], ref: #Reference<0.0.5.5707>, result_formats: [:binary], result_info: [{2950, %Postgrex.TypeInfo{array_elem: 0, base_type: 0, comp_elems: [], input: "uuid_in", oid: 2950, output: "uuid_out", receive: "uuid_recv", send: "uuid_send", type: "uuid"}, Postgrex.Extensions.UUID}], statement: "SELECT u0.\"id\" FROM \"users\" AS u0 LEFT OUTER JOIN \"staff\" AS s1 ON (s1.\"user_id\" = u0.\"id\") AND (1 = $1)", types: 14135761}
[debug] QUERY ERROR source="users" db=2.0ms
SELECT u0."id" FROM "users" AS u0 LEFT OUTER JOIN "staff" AS s1 ON (s1."user_id" = u0."id") AND (1 = $1) []
         (postgrex) lib/postgrex/query.ex:78: DBConnection.Query.Postgrex.Query.encode/3
    (db_connection) lib/db_connection.ex:859: DBConnection.describe_execute/4
    (db_connection) lib/db_connection.ex:930: anonymous fn/4 in DBConnection.run_meter/5
    (db_connection) lib/db_connection.ex:987: DBConnection.run_begin/3
    (db_connection) lib/db_connection.ex:463: DBConnection.prepare_execute/4
             (ecto) lib/ecto/adapters/postgres/connection.ex:78: Ecto.Adapters.Postgres.Connection.prepare_execute/5
             (ecto) lib/ecto/adapters/sql.ex:235: Ecto.Adapters.SQL.sql_call/6
             (ecto) lib/ecto/adapters/sql.ex:424: Ecto.Adapters.SQL.execute_and_cache/7
             (ecto) lib/ecto/repo/queryable.ex:127: Ecto.Repo.Queryable.execute/5
             (ecto) lib/ecto/repo/queryable.ex:40: Ecto.Repo.Queryable.all/4

Expected behavior

A successful query (:happy panda:), or a better error message (:sad panda:).

I know we can use fragments, but this current error is confusing and unexpected. Would love to see this improved!

@stavro
Copy link
Contributor Author

stavro commented Sep 8, 2016

You're amazing.

❤️

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