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

Comparing parameters with constants #123

Open
ghuysmans opened this issue Dec 8, 2024 · 2 comments
Open

Comparing parameters with constants #123

ghuysmans opened this issue Dec 8, 2024 · 2 comments

Comments

@ghuysmans
Copy link

Hi,

I'm building a search webservice using Caqti. The parser rejects my query if it compares input parameters with constants (Parse error at byte xxx: '=' is not allowed after parameter reference '?'); here's a simplified but meaningful example using ppx_rapper:

WHERE %string{mod_}='none' AND NOT EXISTS(SELECT * FROM required_module WHERE id_mission=m.id)
OR EXISTS(SELECT * FROM required_module WHERE id_mission=m.id AND mod_=%string{mod_}))

It can be reduced to a single line of code producing the same error message:

Caqti_query.of_string_exn "SELECT ?=1"

Would it be difficult to modify the parser to handle this case?

Thanks!

@paurkedal
Copy link
Owner

I suggest adding spaces around the equality sign. Sequences of starting with ? followed by operator characters are reserved for future extensions, though the issue gets a bit obscured when using ppx_rapper, making it less obvious why it fails. I'm considering whether the best solution to that may be the adjust ppx_rappers code generator to insert a space in this case.

@ghuysmans
Copy link
Author

Thanks, I completely overlooked that!

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

2 participants