Skip to content

Inserting _query_full_count incorrectly with DISTINCT FROM TRUE syntax #33

Description

Query Helper is adding count(*) over () as _query_full_count column at wrong position when the query has DISTINCT FROM TRUE in it. I think it's confused with FROM.

Database: Snowflake
Pseudo code:

query = "SELECT * from my_table t where 1 = 1 and t.is_deleted is distinct from true"
puts "==========Original Query:"
puts query
puts "==========Query modified by Query Helper:"
query_helper.update(
  query: query,
  model: SnowflakeBuyboxEstimates,
  bind_variables: {}
).results 

Case 1: With 'DISTINCT FROM TRUE' in where condition:

Breaking:

Original query:

SELECT * from my_table t where t.is_deleted is distinct from true

Query Helper modified query:

SELECT * from my_table t where t.is_deleted is distinct , count(*) over () as _query_full_count from true limit 20 offset 0

Case 2: With 'DISTINCT FROM TRUE' in join condition:

Breaking:

Original query:

SELECT * from my_table t join another_table a ON a.id = t.some_id and a.is_deleted is distinct from true

Query Helper modified query:

SELECT * from my_table t join another_table a ON a.id = t.some_id and a.is_deleted is distinct , count(*) over () as _query_full_count from true limit 20 offset 0

Works with brackets:

Original query:

SELECT * from my_table t join another_table a ON (a.id = t.some_id and a.is_deleted is distinct from true)

Query Helper modified query:

SELECT * , count(*) over () as _query_full_count from my_table t join another_table a ON (a.id = t.some_id and a.is_deleted is distinct from true) limit 20 offset 0

This also works:

SELECT * from my_table t where (t.is_deleted is distinct from true)
SELECT * , count(*) over () as _query_full_count from my_table t where (t.is_deleted is distinct from true) limit 20 offset 0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions