1

I am running a query on Postgres table as below:

      Column      |            Type             |     Modifiers
------------------+-----------------------------+--------------------
 status           | character varying(16)  

select FROM incoming_requests WHERE COALESCE(TRIM(status), '') IN ('','OK','ERROR');

This seems to working fine but below not

select FROM incoming_requests WHERE COALESCE(TRIM(status), '') = ANY ('','OK','ERROR');

ERROR:  syntax error at or near ","
LINE 1: ...quests WHERE COALESCE(TRIM(status), '') = ANY (" ","OK","ERR...

select FROM incoming_requests WHERE COALESCE(TRIM(status), '') = ANY (" ","OK","ERROR");

Also suggest if there is any difference in performance using ANY or IN

3
  • 2
    You are missing single quotes around ERROR in the second query. Nov 24 '20 at 22:05
  • 1
    the IN Clause has also a missing single quote
    – nbk
    Nov 24 '20 at 22:17
  • Yeah.. sorry that was a typo. Nov 25 '20 at 4:41
1

No there is no difference

CREATE TABLE incoming_requests ("status" character varying(16) )
select FROM incoming_requests WHERE COALESCE(TRIM(status), '') = ANY (array['', 'OK', 'ERROR']);

db<>fiddle here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.