WHERE in bigint field[]

Asked

Viewed 94 times

2

I have to perform a query to know if the code of a group is in the permissions to see the field.

SELECT *
  FROM callcenter.pausa 
    WHERE habilitado = 1 
     AND permissao_ver::varchar ilike '%1%'
    ORDER BY pausa ASC

Upshot:

{26,9,10,7,19,2,21,11,17,14,15,6,8,25,24,32,27,28,22,23,13,12,16}

This array does not have the number 1 but the same returns me data because there are other numbers with the digit 1, I need it to check that it really has the number 1.

  • If you want it to return you only the data that is the number one why is using the like?

1 answer

4


Rafael,

You can use the &&operator, it compares two array and if any element exists in the two it returns true (as if it were an "OR").

Assuming this permissa_ver field is a bigint[], you can do the command as an example:

SELECT *
FROM callcenter.pausa 
WHERE habilitado = 1 
AND permissao_ver && '{1}'::bigint[]
ORDER BY pausa ASC

You can see more details in the postgres documentation: https://www.postgresql.org/docs/current/static/functions-array.html#ARRAY-OPERATORS-TABLE

Browser other questions tagged

You are not signed in. Login or sign up in order to post.