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

Reusing the same parameter in WHERE fails to parse #99

Closed
typeofweb opened this issue Jun 5, 2020 · 0 comments · Fixed by #101
Closed

Reusing the same parameter in WHERE fails to parse #99

typeofweb opened this issue Jun 5, 2020 · 0 comments · Fixed by #101

Comments

@typeofweb
Copy link
Contributor

typeofweb commented Jun 5, 2020

The problem

Using the same argument in 2 places inside a WHERE fails to parse. For example:

/*
  @name FindAllQuestions1
*/
SELECT id FROM "Question" WHERE ( ( :category IS NULL ) OR ( "_categoryId" = :category ) );

Results in:

Error in query. Details: {
  errorCode: 'scanner_yyerror',
  hint: undefined,
  message: 'syntax error at or near ":"',
  position: '37'
}

However, if I keep the query almost the same but just remove one :category, it works:

/*
  @name FindAllQuestions2
*/
SELECT id FROM "Question" WHERE ( ( 123 IS NULL ) OR ( "_categoryId" = :category ) );

(No errors)

/*
  @name FindAllQuestions3
*/
SELECT id FROM "Question" WHERE ( ( :category IS NULL ) OR ( "_categoryId" = 'foo' ) );

(could not determine data type of parameter $1, which makes sense and it parsed just fine)

DB Logs

Looking at my database logs I can't help but notice that the first usage of the parameter was not replaced by $1:

db_1  | 2020-06-05 13:47:55.249 UTC [2572] ERROR:  syntax error at or near ":" at character 37
db_1  | 2020-06-05 13:47:55.249 UTC [2572] STATEMENT:  SELECT id FROM "Question" WHERE ( ( :category IS NULL ) OR ( "_categoryId" = $1 ) )
@typeofweb typeofweb changed the title Reusing the same parameter in WHERE failes to parse Reusing the same parameter in WHERE fails to parse Jun 5, 2020
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

Successfully merging a pull request may close this issue.

1 participant