问题
I am having a problem with building postgres query. I am using Slick in Scala to connect to the database. However, in a few cases, I need to manually add some extra where clause to the slick generated query. Slick is generating the query with alias for the columns, but while appending the extra where condition, I do not know the alias name slick has given. So I am trying to use the table name and column name directly, but facing issues with the query.
SELECT x2.x3,
x2.x4,
x5.x6
FROM (
SELECT x7."SkillId" AS x3,
x7."Name" AS x4,
x7."Description" AS x8,
x7."IsRemoved" AS x9,
x7."SkillCategoryId" AS x10
FROM "base"."Skill" x7
) x2
INNER JOIN (
SELECT x11."SkillCategoryId" AS x12,
x11."Name" AS x6,
x11."Description" AS x13,
x11."IsRemoved" AS x14
FROM "base"."SkillCategory" x11
) x5 ON x2.x10 = x5.x12
WHERE base."Skill"."IsRemoved" = 'false'
LIMIT 10 offset 0
The above query is giving the error as
ERROR: missing FROM-clause entry for table "Skill"
LINE 3: where base."Skill"."IsRemoved" = 'false' LIMIT 10 OFFSET 0
However, If I change the where clause to where x2.x9 = 'false' LIMIT 10 OFFSET 0
, the query executes successfully.
But I can not know what is the alias(x2 and x9
), so can't change the query in the code accordingly.
Is there a way to fix this problem ?
来源:https://stackoverflow.com/questions/27937118/use-table-name-instead-of-its-alias-in-the-postgres-query