1

I have a simple db table:

create table if not exists players
(
  id bigint,
  name text,
  results text[]
);

Now I would like to create select query, where I want only rows with passed results. So I created a scala code with doobie:

def getPlayers(id: Int, result: String): Query[Int] = {
  sql"select id from players where results ? $result".query[Int]
}

But it didn't work as expected. My question is how to select from array column in postgresql? Currently I have results as an array, but I could change it to jsonb if it is easier.

1
  • instead of ? operator you should use @> operator and `$result should be text array
    – Sahap Asci
    Commented Jan 5, 2023 at 11:26

1 Answer 1

0

You can use the following query:

select id from players where $result = any(results);

You can find more information here:

https://www.postgresql.org/docs/current/functions-comparisons.html

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