Linked Questions
33 questions linked to/from How to use ANY instead of IN in a WHERE clause?
2 votes
1 answer
2k views
PostgreSQL =ANY and IN [duplicate]
Recently I've read Quantified Comparison Predicates – Some of SQL’s Rarest Species: In fact, the SQL standard defines the IN predicate as being just syntax sugar for the = ANY() quantified ...
328 votes
8 answers
517k views
Check if value exists in Postgres array
Using Postgres 9.0, I need a way to test if a value exists in a given array. So far I came up with something like this: select '{1,2,3}'::int[] @> (ARRAY[]::int[] || value_variable::int) But I ...
268 votes
4 answers
296k views
Select rows which are not present in other table
I've got two postgresql tables: table name column names ----------- ------------------------ login_log ip | etc. ip_location ip | location | hostname | etc. I want to get every IP ...
350 votes
3 answers
508k views
IN vs ANY operator in PostgreSQL
What is the difference between IN and ANY operator in PostgreSQL? The working mechanism of both seems to be the same. Can anyone explain this with an example?
20 votes
4 answers
31k views
Find rows where text array contains value similar to input
I'm trying to get rows where a column of type text[] contains a value similar to some user input. What I've thought and done so far is to use the 'ANY' and 'LIKE' operator like this: select * from ...
14 votes
3 answers
25k views
PL/pgSQL SELECT into an array
Here's my function declaration and part of the body: CREATE OR REPLACE FUNCTION access_update() RETURNS void AS $$ DECLARE team_ids bigint[]; BEGIN SELECT INTO team_ids "team_id" FROM "...
13 votes
4 answers
3k views
Django query filter using large array of ids in Postgres DB
I want to pass a query in Django to my PostgreSQL database. When I filter my query using a large array of ids, the query is very slow and goes up to 70s. After looking for an answer I saw this post ...
7 votes
2 answers
8k views
How to pass custom type array to Postgres function
I have a custom type CREATE TYPE mytype as (id uuid, amount numeric(13,4)); I want to pass it to a function with the following signature: CREATE FUNCTION myschema.myfunction(id uuid, mytypes mytype[...
6 votes
2 answers
8k views
Sending array of values to a sql query in ruby?
I'm struggling on what seems to be a ruby semantics issue. I'm writing a method that takes a variable number of params from a form and creates a Postgresql query. def self.search(params) counter ...
10 votes
1 answer
6k views
Use Values from JSONB Array inside a WHERE IN Clause
I have a JSONB object in PostgreSQL: '{"cars": ["bmw", "mercedes", "pinto"], "user_name": "ed"}' I am trying to use values from the "cars" array inside it in the WHERE clause of a SELECT: SELECT ...
3 votes
1 answer
4k views
What is the most performant way to rewrite a large IN clause?
I wrote an API using go and gorm that runs calculations on our database and returns the results. I just hit the parameter limit for an IN condition when using an aggregate. Example query: SELECT SUM(...
4 votes
1 answer
3k views
Postgres IN clause with many values not using partial index
I am using Postgres 9.2.24. I have a table named _order with about 100,000,000 rows. The table has a column named merged_id int8. About 2,000,000 of the _order rows have a merged_id value, the rest ...
0 votes
2 answers
15k views
Distinct values from an array?
Following tables: CREATE TEMPORARY TABLE guys ( guy_id integer primary key, guy text ); CREATE TEMPORARY TABLE sales ( log_date date, sales_guys integer[], sales smallint ); INSERT INTO guys VALUES(1,...
1 vote
2 answers
3k views
PostgreSQL: Issue with passing array to procedure
I have a type as: CREATE TYPE status_record AS ( id bigint, status boolean ); A procedure that does some processing with an array of type as input parameter as: CREATE OR REPLACE ...
2 votes
2 answers
4k views
SQL SELECT that excludes rows with any of a list of values?
I have found many Questions and Answers about a SELECT excluding rows with a value "NOT IN" a sub-query (such as this). But how to exclude a list of values rather than a sub-query? I want to search ...