0

I red a bunch of questions about handling NULL values in rust-postgresql, but they don't mention my personal case.

I need to select rows using a WHERE with a parameter that can be NULL, like

SELECT id FROM TABLE WHERE name=$1

If the Option used to set $1 is None, it doesn't retrieve any rows. So i have to split the query under a IF, like


if myname.is_some()

    SELECT id FROM TABLE WHERE name=$1
else

    SELECT id FROM TABLE WHERE name=NULL

There is a better way to handle a NULL in a WHERE clause with a single line of code?

I tried to handle it with the "default" way. I hope there is a faster way.

Rottame
  • 21
  • 3

0 Answers0