Skip to content

How to declare a param as nullable? #451

Answered by kyleconroy
maxhawkins asked this question in General
Discussion options

You must be logged in to vote

Is it possible to make the type of a parameter nullable for just one query?

Not currently. This goes back to #210, in which we discussed that all SQL parameters can be NULL. It's probably too late to change the existing default behavior.

There are a few options we can consider. One would be a global setting emit_nullable_params, which would make all parameters null. My guess is that this wouldn't be very helpful, as you're looking for control at the query level.

Another option would be to fix #133 and properly support NULLIF. You could then write

SELECT *
FROM foo
WHERE
  id = NULLIF(@user_id, '')
  OR email = NULLIF(@email, '')

This probably works for your query, but there are queries …

Replies: 8 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@imraan-go
Comment options

Answer selected by kyleconroy
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants
Converted from issue

This discussion was converted from issue #451 on August 23, 2020 20:01.