24

I have a generated Postgres query

select ..., s.name as supplier, ...
from ... supplier s ...
where ...
      AND (cast(supplier as varchar(255)) ilike '%test%')
      ...
ORDER BY supplier desc nulls last

I get this error:

org.postgresql.util.PSQLException: ERROR: column "supplier" does not exist

if I replace the "supplier" with s.name then it's ok but I can't do that. I have this issue on other columns too but there are columns which are working fine.

There are some restriction that I can't use alias the same as the table name or what can be the problem?

Zsolt Balogh
  • 595
  • 1
  • 5
  • 12

1 Answers1

20

I found the explanation here: http://www.postgresql.org/message-id/18195.1038530280@sss.pgh.pa.us

I can't use the alias from the select in the WHERE clause.

Lee Chee Kiam
  • 11,450
  • 10
  • 65
  • 87
Zsolt Balogh
  • 595
  • 1
  • 5
  • 12