Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 879CC9FB1EC for ; Sun, 8 Oct 2006 22:04:27 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 85405-08 for ; Mon, 9 Oct 2006 01:04:20 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.190]) by postgresql.org (Postfix) with ESMTP id ABC529FA4A0 for ; Sun, 8 Oct 2006 22:04:19 -0300 (ADT) Received: by nf-out-0910.google.com with SMTP id m18so1661054nfc for ; Sun, 08 Oct 2006 18:04:18 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=hQ6tJwmUelnuRR12r8bOMaRuV7I2aLtGQi8IH4nkAQm6QXansr5BRUWQyxTt925Fu5od4GKxFFBnP4GBTLVGPQfpb5FT7B0euw05oqDUcl1KANz2e8AWIEFerOeXIub+Tp5dMQmOCvD//ks/LNTMUnYDjoVrv5NbwnRKvYU28+A= Received: by 10.48.48.15 with SMTP id v15mr935775nfv; Sun, 08 Oct 2006 14:04:03 -0700 (PDT) Received: by 10.48.164.13 with HTTP; Sun, 8 Oct 2006 14:04:02 -0700 (PDT) Message-ID: <5d0f60990610081404s79a90cdbha4603c70c75ce233@mail.gmail.com> Date: Sun, 8 Oct 2006 23:04:02 +0200 From: "Dirk Jagdmann" To: pgsql-sql@postgresql.org Subject: optimal insert MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200610/89 X-Sequence-Number: 26478 Hello experts, I have a database that contains three tables: create table a ( id serial primary key, ... -- some more fields not relevant for my question ); create table b ( id serial primary key, ... -- some more fields not relevant for my question ); create table a_b ( a int not null references a, b int not null references b ); Tables a and b have already been filled with lots of rows. Now my application needs to insert the relationship of a to b into table a_b and is currently doing it with inserts like the following: insert into a_b(a,b) values(1,100); insert into a_b(a,b) values(1,200); insert into a_b(a,b) values(1,54); insert into a_b(a,b) values(1,4577); So for a batch of inserts the value of a stays the same, while for by arbitrary values are inserted. Now I have wondered if PostreSQL offers a smarter way to insert those values? A solution can contains usage of some plpgsql code. -- ---> Dirk Jagdmann ----> http://cubic.org/~doj -----> http://llg.cubic.org