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

[NFR] PostgreSQL row sorting: implement [NULLS { FIRST | LAST }] #548

Closed
globalundo opened this issue Apr 15, 2013 · 7 comments
Closed

[NFR] PostgreSQL row sorting: implement [NULLS { FIRST | LAST }] #548

globalundo opened this issue Apr 15, 2013 · 7 comments

Comments

@globalundo
Copy link

globalundo commented Apr 15, 2013

Currently, on executing following piece of code:

$robots = Robots::find(array(
    "order" => "name DESC NULLS LAST"
));

Exception rises:

Phalcon\Mvc\Model\Exception: Syntax error, unexpected token IDENTIFIER(NULLS), near to ' LAST'
@phalcon
Copy link
Collaborator

phalcon commented Apr 15, 2013

How could that syntax be rewritten to work on Mysql and Sqlite?

@globalundo
Copy link
Author

As far as I'm concerned, there is no native NULLS { FIRST | LAST }, but there are some workarounds http://stackoverflow.com/questions/1498648/sql-how-to-make-null-values-come-last-when-sorting-ascending
http://stackoverflow.com/questions/12503120/how-to-do-nulls-last-in-sqlite for mysql and sqlite respectively.

@roman-kulish
Copy link

@phalcon Why should it even work in Sqlite and MySQL? I see no reason for it. If somebody wants to use advanced database features then framework should provide this possibility, otherwise it is a framework limitation. If framework tends to be compatible with all databases it should be flexible, but not impose limitations.

@phalcon
Copy link
Collaborator

phalcon commented May 12, 2013

Because the goal of PHQL is transparent switch between the supported databases. Support every possible no sql-standard syntax is almost impossible. Also, we can't automatically escape columns/table names or rename columns if PHQL is not used.

@igorgolovanov
Copy link
Contributor

Can be solved by #653

$di->modelsManager->registerSimpleQueryFunction('ORDER_BY_NULLS_LAST', '?0 NULLS LAST');

$robots = Robots::find(array(
    "order" => "name ORDER_BY_NULLS_LAST(DESC)"
));

// SELECT u.* FROM users AS u ORDER BY u.name DESC NULLS LAST 

@sergeyklay
Copy link
Contributor

This belongs in Incubator Dialect.

@sergeyklay
Copy link
Contributor

This issue was moved to phalcon/incubator#801

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants