Contributors mailing list archives

contributors@odoo-community.org

Browse archives

Avatar

Re: Empty SQL argument and ANY operator

by
DEC, Yann Papouin
- 29/05/2024 09:08:35
After a few months, I'm coming back on this issue as my initial dirty fix was wrong, the culprit comes from the hard-coded SQL query because the following statement is invalid:
  and p.id != ANY(%s)
and should be replaced with following statement to have the expected result
  and not p.id = ANY(%s)

That's awkward as it works perfectly for
and (p.email != ANY(%s) or p.email is null)

---------------------------------------------------------------
SELECT
P.ID, P.EMAIL
FROM
RES_PARTNER P

"id","email"
1,"contact1@dec.sarl"
2,"contact2@dec.sarl"
3,"contact3@dec.sarl"
4,null

---------------------------------------------------------------
SELECT
P.ID,
P.EMAIL
FROM
RES_PARTNER P
WHERE
p.id != ANY((ARRAY[1,2]))

"id","email"
1,"contact1@dec.sarl"
2,"contact2@dec.sarl"
3,"contact3@dec.sarl"
4,NULL

---------------------------------------------------------------
SELECT
P.ID,
P.EMAIL
FROM
RES_PARTNER P
WHERE
not p.id = ANY((ARRAY[1,2]))

"id","email"
3,"contact3@dec.sarl"
4,NULL

---------------------------------------------------------------
SELECT
P.ID,
P.EMAIL
FROM
RES_PARTNER P
WHERE
NOT P.EMAIL = ANY ((ARRAY['contact1@dec.sarl']))
OR P.EMAIL IS NULL

"id","email"
2,"contact2@dec.sarl"
3,"contact3@dec.sarl"
4,NULL

---------------------------------------------------------------
SELECT
P.ID,
P.EMAIL
FROM
RES_PARTNER P
WHERE
P.EMAIL != ANY ((ARRAY['contact1@dec.sarl']))
OR P.EMAIL IS NULL

"id","email"
2,"contact2@dec.sarl"
3,"contact3@dec.sarl"
4,NULL

Reference