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

PG::SyntaxError: ERROR: syntax error at or near "desc" #27

Open
khiav223577 opened this issue Sep 18, 2019 · 0 comments
Open

PG::SyntaxError: ERROR: syntax error at or near "desc" #27

khiav223577 opened this issue Sep 18, 2019 · 0 comments

Comments

@khiav223577
Copy link

I have a model with a column named desc.

It works fine when using pluck

Mission.where(id: 1).union(id: 2).pluck('desc')
# SELECT "missions"."desc" FROM ( (SELECT "missions".* FROM "missions" WHERE "missions"."id" = $1) UNION (SELECT "missions".* FROM "missions" WHERE "missions"."id" = $2) ) "missions"  [["id", 1], ["id", 2]]

But it is broken when using select

Mission.where(id: 1).union(id: 2).select('desc')
# SELECT  desc FROM ( (SELECT "missions".* FROM "missions" WHERE "missions"."id" = $1) UNION (SELECT "missions".* FROM "missions" WHERE "missions"."id" = $2) ) "missions" LIMIT $3  [["id", 1], ["id", 2], ["LIMIT", 11]]

# ActiveRecord::StatementInvalid (PG::SyntaxError: ERROR:  syntax error at or near "desc")
# LINE 1: SELECT  desc FROM ( (SELECT "missions".* FROM "missions" WHE...
#                 ^
# : SELECT  desc FROM ( (SELECT "missions".* FROM "missions" WHERE "missions"."id" = $1) # UNION (SELECT "missions".* FROM "missions" WHERE "missions"."id" = $2) ) "missions" # LIMIT $3

It seems that it fails to quote the column desc as "missions"."desc"

Environment

Rails version: 5.2.1
ruby version: 2.5.1
active_record_union: 1.3.0

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