Use table name instead of its Alias in the postgres Query

喜欢而已 提交于 2019-12-25 04:04:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!