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

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

1 Answer 1

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

answered Nov 24, 2020 at 21:43

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.