mvysny / vok-orm

Mapping rows from a SQL database to POJOs in its simplest form

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Aliased columns do not work with SQLDataLoader

mvysny opened this issue · comments

MySQL nor PostgreSQL does not support aliases in WHERE clauses: https://stackoverflow.com/questions/942571/using-column-alias-in-where-clause-of-mysql-query-produces-an-error
Therefore we can't use the java bean property names when constructing the WHERE clause, but we must use the actual column names.

The workaround would be to use HAVING instead of WHERE with MySQL, but it's slower and not actually supported by the PostgreSQL (actually it looks like it's supported by newer PostgreSQLs 9.x - evaluate).

All of the following databases fail to execute this statement:

  • H2 1.4.197
  • PostgreSQL 10.3
  • MySQL 5.7.21
  • MariaDB 10.1.31
SELECT count(*) FROM (select p.name as personName from Test p where 1=1 and personName = ? order by 1=1 ) AS Foo

The error message is 'unknown column personName'.

Ok, it's explicitly mentioned in PostgreSQL SELECT documentation:

An output column's name can be used to refer to the column's value in ORDER BY and GROUP BY clauses, but not in the WHERE or HAVING clauses; there you must write out the expression instead.

Fixed in vok-orm 0.9