pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Neu <peter.neu@gmx.net>
To: pgsql-jdbc@postgresql.org
Subject: Efficient Insert statement for one record into multiple tables?
Date: Mon, 18 Dec 2006 10:53:39 +0100
Message-ID: <01cd01c7228a$6680d960$bcc8a8c0@PCMELZER> (raw)

Hello,

 

I have this task that I need to insert one user record into to tables A and
B. 

 

User table A contains primary key and main data. Table B contains extra data
for

statistics. Table A has one field Id which is a sequence so it gets a unique
value 

for each new insert. I would like to insert this value into the other table
B as well as 

foreign key. 

 

So I'd like to do something like this 

 

insert into A (user_name, value2 ) values ( "foo", "foo2") 

 

AND 

 

insert into B ( id_from_a , statistic_data) values ( 23, "bla")

 

How is this done the best way? I would like to do this in one call. 

 

Sorry, for his dumb question but I'm not very experienced in Postgresql. :o(

 

 

Cheers,

 

Pete

 

 

 

 

 

 

 

 

view thread (13+ messages)  latest in thread

Message-ID: <01cd01c7228a$6680d960$bcc8a8c0@PCMELZER>
Permalink:  ../01cd01c7228a$6680d960$bcc8a8c0@PCMELZER/
Also on:    postgresql.org/message-id/01cd01c7228a$6680d960$bcc8a8c0@PCMELZER

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: peter.neu@gmx.net
  Subject: Re: Efficient Insert statement for one record into multiple tables?
  In-Reply-To: <01cd01c7228a$6680d960$bcc8a8c0@PCMELZER>
  References: <01cd01c7228a$6680d960$bcc8a8c0@PCMELZER>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox