Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aliased columns do not work with SQLDataLoader #5

Closed
mvysny opened this issue Sep 11, 2018 · 4 comments
Closed

Aliased columns do not work with SQLDataLoader #5

mvysny opened this issue Sep 11, 2018 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@mvysny
Copy link
Owner

mvysny commented Sep 11, 2018

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.

@mvysny mvysny self-assigned this Sep 11, 2018
@mvysny mvysny added the bug Something isn't working label Sep 11, 2018
@mvysny
Copy link
Owner Author

mvysny commented Sep 11, 2018

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).

@mvysny
Copy link
Owner Author

mvysny commented Sep 11, 2018

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'.

@mvysny
Copy link
Owner Author

mvysny commented Sep 11, 2018

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.

@mvysny mvysny closed this as completed in 77a307a Sep 11, 2018
@mvysny
Copy link
Owner Author

mvysny commented Sep 11, 2018

Fixed in vok-orm 0.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant