active_record_union
active_record_union copied to clipboard
PG::SyntaxError: ERROR: syntax error at or near "desc"
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