Applies to: PostgreSQL, as reported (no version named); the Clarion version is not named.
Problem
After moving from Pervasive to PostgreSQL, SELECT column_name AS alias_name FROM table_name WHERE alias_name = 'Juan' returned that alias_name does not exist. The poster wanted the same with scalar subqueries as columns, for example (select sum(...) ...) as clientevale, then WHERE clientevale = 45454 OR clienteremisones = 12345, without repeating the long subselects.
Solution
- Filter on the real expression, not the alias:
WHERE column_name = 'Juan'. A column alias in the select list cannot be used in the WHERE of the same select; Jon W. said this is not standard SQL. - Wrap the select and filter outside it:
select * from (select x as y from t) where y = 'constant'. - Use a WITH query (the PostgreSQL "queries-with" documentation page); the poster adopted this one.
- For calculated columns, treat each one as a table: LEFT JOIN a grouped subselect (
select factura, serie, sum(abono) as totalabonado from chequefactura group by factura, serie) onto the main table and filter on the joined columns. Jon W. preferred ANSI joins so the ON part is the join and the WHERE part is the filter.
Caveats
- Use LEFT joins for the sums, because an inner join drops the rows that have no match. If the WHERE always filters on those tables, an inner join on them is probably a little more efficient.
- Jon W. tested a PROP:SQL that begins with WITH:
next()did not return the values, while the same query starting with SELECT did. A WITH query is fine on the server, not as the start of a PROP:SQL (see FAQ-394 in batch 8). - A stored procedure around the same SQL gains nothing, as Jon W. put it. A Clarion file alias is a different thing from an SQL alias (Stamos).
Today (2026)
Likely unchanged: the alias rule is a property of SQL, not of Clarion. The PROP:SQL remark was not re-tested.
Sources: Jose L. (Dec 2012, the question), Stamos, Geoff B., Jon W. (Dec 2012) in softvelocity.clarion.databasedrivers.