Skip site navigation (1) Skip section navigation (2)

Re: Specifying many rows in a table

From: Greg Stark <gsstark(at)mit(dot)edu>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Specifying many rows in a table
Date: 2004-01-30 05:11:22
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-general
"scott.marlowe" <scott(dot)marlowe(at)ihs(dot)com> writes:

> The optimizations made for in() queries in the 7.4 branch only really work 
> when there's a subselect / table in the in.  You could try inserting those 
> numbers into a temp table and subselecting it.  

I'll second this option.

But the other choice is to use a prepared statement like "select * from tab
where tab_id = ?" and simply execute it 10,000 times with different

This involves lots of round trips to the server and is a lot less efficient,
but it doesn't require building a temporary table, which might be an
advantage. In fact if the data is coming from outside the database then you'll
probably end up building the temporary table using lots of executions like
this anyways, so it might not really be a disadvantage.

In the future the the ideal solution might be to have array processing support
in postgres, where you prepare a statement then ship the server an array of
parameter lists and the server executes the statement once for each array
element. Ideally it would let you stream the array to the server and it
execute them as fast as you can ship the data, avoiding round trip latency.
But I don't think there's any such support in postgres currently.


In response to

pgsql-general by date

Next:From: SusemailDate: 2004-01-30 05:28:47
Subject: No Database Drivers
Previous:From: Alvaro HerreraDate: 2004-01-30 02:04:53
Subject: Re: I can't upgrade to PostgreSQL 7.4 in RedHat 9.0

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group