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?
In PostgreSQL, an alias is a temporary alternative name for columns, tables, views, materialized views, etc. in a query. Aliases are assigned during query execution and aren't stored in the database or on disk. By using column aliases, the query output can become more meaningful.
The WHERE clause can contain non-correlated aliases and correlated aliases.
Column AliasSELECT column_name AS alias_name FROM table; or, SELECT column_name alias_name FROM table; Below Syntax is for column alias used with expressions: SELECT expression alias_name FROM table; The primary use of column alias is to make the output of a query more meaningful.
In PROC SQL, a column alias can be used in a WHERE clause, ON clause, GROUP BY clause, HAVING clause, or ORDER BY clause. In the ANSI SQL standard and ISO SQL standard, the value that is associated with a column alias does not need to be available until the ORDER BY clause is executed.
I found the explanation here: http://www.postgresql.org/message-id/[email protected]
I can't use the alias from the select in the WHERE clause.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With