0

I have the following case in PostgreSQL:

    xfields smallint[];
    xfields={1,2,3}

   select fields from table where fieldno not in (xfields);

if i execute the above query it shows error as " operator does not exist: smallint <> smallint[] "

can anyone help me how to pass the values in array in the above query or how to execute the above conditions?

2 Answers 2

2

You can use array in query by using ALL or ANY functions.

For above query you can use

select fields from table where fieldno <> ALL(xfields);

Check here

Sign up to request clarification or add additional context in comments.

2 Comments

please don't give links to old versions, OP uses 9.1, your link is to 8.2
@Roman: Thanks for the tip. I was trying to answer as quick as possible. My +1 goes to you for fiddle demo.
2

Documentation about it's here Row and Array Comparisons v 9.1 or latest version.

select fields
from table
where fieldno <> all(xfields);

=> sql fiddle demo

Comments

Your Answer

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.