0
votes

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 ?

x2 is an alias for second subquery and x9 is an alias of IsRemoved field. - Maciej Los
Yeah, that I understand. But the x2 and x9 aliases are created by Slick, on which I have no control. I will not be able to get the alias of subquery and isRemoved field to append the where condition. - Yadu Krishnan
Simple answer: there is no table named "Skill" in your query any more. Any reference to it must use the alias. If you don't want that, then don't use the alias - a_horse_with_no_name
hmmm :( Since I dont have control of the alias name slick provides, I cant get the alias names to be added to the where condition. :( - Yadu Krishnan