0

I have an array in SQL like

CREATE TABLE Table1 (
examples text ARRAY);

INSERT INTO Table1 
(examples)
VALUES
{t1,t2,t3};

I can't find a description of the correct syntax to do select * from Table1 where (values) in (any\some) examples I tried the tutorial example but it doesn't work or I just don't understand something

select *
from player_scores
where 95 < any (round_scores);

Do I understand correctly that you need to do something like this -

Postgresql Select rows where column = array or this - How to check if any field of array not contains substring in Postgres?

SELECT * FROM Table1 WHERE "value" = any (examples); 
2
  • You need to use single quotes instead of double quotes dbfiddle.uk/oiD2UpVP Commented Oct 13, 2023 at 9:23
  • Done! SELECT * FROM TABLE1 WHERE 'VALUE' = ANY(examples) Commented Oct 13, 2023 at 9:24

2 Answers 2

1

DB fiddle

Your query should be:

select *
from player_scores
where '95' = ANY(round_scores);

You can check this answer too.

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

Comments

0

How to check, is (value) in postgres sql (array)?

Yes, it is correct. if you want to check whether a value is in a PostgreSQL array, you can use function ANY(). ANY() returns true if the value is present in the array, and false otherwise.

Furthermore you need to use single quotes instead of double quotes when using ANY() with arrays in PostgreSQL. The reason is ANY() expects the array elements to be enclosed in single` quotes:

SELECT * FROM player_scores WHERE '95' = ANY(round_scores);

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.