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.

Query builder regression in 0.2

See original GitHub issue

Issue type:

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

Database system/driver:

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

TypeORM version:

[X] latest [ ] @next [X] 0.1.20 (or put your version here)

Steps to reproduce or a small repository showing the problem:

Query builder generated SQL changed after upgrade to 0.2 in a way that affects results. This

connection
  .getRepository(Model)
  .createQueryBuilder('model')
  .select('id')
  .whereInIds([ 1, 2 ])
  .andWhere('column = 1')
  .getMany());

produces

WHERE ("model"."id" = $1) OR ("model"."id" = $2) AND column = 1 -- PARAMETERS: [1,2]

in 0.2.5, and

WHERE ("model"."id"=$1 OR "model"."id"=$2) AND column = 1 -- PARAMETERS: [1,2]

in 0.1.20. Because of the parentheses over id conditions have changed, a different set of results is returned. If the order of the conditions is changed to

connection
  .getRepository(Model)
  .createQueryBuilder('model')
  .select('id')
  .where('column = 1')
  .andWhereInIds([ 1, 2 ])
  .getMany());

the generated SQL is

WHERE column = 1 AND (("model"."id" = $1) OR ("model"."id" = $2)) -- PARAMETERS: [1,2]

for 0.2.5 and

WHERE column = 1 AND ("model"."id"=$1 OR "model"."id"=$2) -- PARAMETERS: [1,2]

for 0.1.20, and both thus return the same results.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
silentroachcommented, Jan 18, 2019

yep, I know how to fix it and will try to do this in few days 😃

1reaction
pleerockcommented, May 9, 2018

okay, so if it does following query:

select * from items where (id = 3) or (id = 2) and x = 1;

then we shall make a fix to make it this way:

select * from items where ((id = 3) or (id = 2)) and x = 1;

Read more comments on GitHub >

github_iconTop Results From Across the Web

0.3.7 (2022-06-29) | TypeORM Docs
Use QueryBuilder to build queries containing manual joins. Connection , ConnectionOptions are deprecated, new names to use are: DataSource and DataSourceOptions ...
Read more >
Bulk update via raw query in TypeORM - Stack Overflow
How can I do bulk update via raw query in TypeORM? ... How can I change names of few users in one transaction?...
Read more >
typeorm: CHANGELOG
Use QueryBuilder to build queries containing manual joins.
Read more >
Machine Learning: Polynomial Regression with Python
test_size=0.2 : we will split our dataset (10 observations) into 2 parts (training set, test set) and the ratio of test set compare...
Read more >
Changelog | Objection.js - GitHub Pages
fix regression: QueryBuilder.from is broken. # 0.3.2. # What's new. Improved relation expression whitespace handling. # 0.3.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