question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ORDERBY case insensitive

See original GitHub issue

Issue type:

[ ] question [ ] bug report [X] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [ ] mysql / mariadb [ ] oracle [X] postgres [ ] cockroachdb [ ] sqlite [ ] sqljs [ ] react-native [ ] expo

TypeORM version:

[X] latest [ ] @next [ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

We currently can’t make a case insensitive orderBy (using orderBy of querybuilder)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

9reactions
iFonnycommented, Aug 7, 2019

@Ginden I don’t know what I’ve changed but its working fine now (even without LOWER()) But it’s not working if I’m sorting using a field of a joined table

for .orderBy('LOWER(information.streetAddress)') (information is a OneToOne relation in user table)

Error: "LOWER(information" alias was not found. Maybe you forgot to join it?
    at QueryExpressionMap.findAliasByName (/Users/ifonny/Travail/Lucette/Lucette-API-nestjs/src/query-builder/QueryExpressionMap.ts:341:19)
    at /Users/ifonny/Travail/Lucette/Lucette-API-nestjs/src/query-builder/SelectQueryBuilder.ts:1864:54
    at Array.map (<anonymous>)
    at SelectQueryBuilder.createOrderByCombinedWithSelectExpression (/Users/ifonny/Travail/Lucette/Lucette-API-nestjs/src/query-builder/SelectQueryBuilder.ts:1861:14)
    at SelectQueryBuilder.<anonymous> (/Users/ifonny/Travail/Lucette/Lucette-API-nestjs/src/query-builder/SelectQueryBuilder.ts:1779:46)
    at step (/Users/ifonny/Travail/Lucette/Lucette-API-nestjs/node_modules/tslib/tslib.js:133:27)
    at Object.next (/Users/ifonny/Travail/Lucette/Lucette-API-nestjs/node_modules/tslib/tslib.js:114:57)
    at /Users/ifonny/Travail/Lucette/Lucette-API-nestjs/node_modules/tslib/tslib.js:107:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/Users/ifonny/Travail/Lucette/Lucette-API-nestjs/node_modules/tslib/tslib.js:103:16)

But the request is working If I printSql() and run it manually. Looks like it consider ‘LOWER(’ as part of the alias

6reactions
emsitracommented, Jul 21, 2021

I’ve found an alternative way to solve the issue with the thrown ‘alias was not found’ error. Just added a temporary field with an alias while building a query which helped me to make case insensitive sorting.

e.g. you wanna use : .orderBy('LOWER(information.streetAddress)')

Change it to these expressions in your QB and it should work:

.addSelect('LOWER("information"."streetAddress")', 'info_st_address')
.orderBy('info_st_address', 'ASC')
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use SQL Order By statement to sort results case ...
Yes, there's no way to change the behavior of ORDER BY to be case-insensitive. – Chad Birch. Mar 9, 2010 at 23:37. 2....
Read more >
Case Insensitive ORDER BY clause using COLLATE
Case -sensitive sorting is guaranteed order between cases of the same letter: (a,a,A,A,b), case-insensitive sorting is not: (a,A,a,A,b), (A,a,a,A,b), etc, or ...
Read more >
How to use SQL Order By statement to sort results ... - Intellipaat
I have an SQLite database that I am trying to sort by Alphabetical order. The problem is, SQLite ... know about? SELECT *...
Read more >
Case-sensitivity quirks with Velocity sorts - Marketing Nation
By “alphabetically,” those folks mean case-insensitive sort order, where uppercase/lowercase pairs (in the local language) are treated as ...
Read more >
Case-insensitive using 'ORDER BY' - SQLite Forum
I'm confused a bit by the ORDER BY operator. I would like it to be case-insensitive. I already have enabled 'case_sensitive_like = 1'...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found