skip to Main Content

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 (anysome) 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

Answers


  1. DB fiddle

    Your query should be:

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

    You can check this answer too.

    Login or Signup to reply.
  2. 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);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search