Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Verz9-0001vY-CA for pgsql-sql@arkaria.postgresql.org; Fri, 08 Nov 2013 19:44:51 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Verz8-0005YO-LR for pgsql-sql@arkaria.postgresql.org; Fri, 08 Nov 2013 19:44:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Verz7-0005Wq-1k for pgsql-sql@postgresql.org; Fri, 08 Nov 2013 19:44:49 +0000 Received: from mail-ea0-x22d.google.com ([2a00:1450:4013:c01::22d]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Verz4-00088D-FI for pgsql-sql@postgresql.org; Fri, 08 Nov 2013 19:44:48 +0000 Received: by mail-ea0-f173.google.com with SMTP id g10so1350589eak.18 for ; Fri, 08 Nov 2013 11:44:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=GDLoFIENjvIw95bgsGreedRzB8YFJ1YXgdkGqj0UJ+4=; b=wk8909XTP64rWDrUJx1yLqZjIIs6Y33A92SaIpZ8YFRW3O/Q/HVAEGDs7i1tLXqDux +ahg8XBaOdeypfrv/7DdglWFLG4Iy+hQ0fjAv+zo7mjMjhCQBx5ZnLr8gvmSJ0TTqy/n E+OBDURhAFmo9d5BLWv+v6Uk87OwdAvnrZ//b88S4bfikAehJeW+DwXYHjG8+NKzHh44 hI6speuqyHqPBBioeE9Y0lCedXciQBSri4TqigzcG/2wNtW/LXh56uuIX2MeIj9v6QBL EurrEGdXH9utcTYyuXNl8eyHsx7aOjv6t3nU0G+QljEGTfhXa8M0DT5qp4zWn/n3wZWU rJRQ== X-Received: by 10.14.100.196 with SMTP id z44mr18968588eef.2.1383939883957; Fri, 08 Nov 2013 11:44:43 -0800 (PST) Received: from [192.168.178.35] (byrt-4d0719cc.pool.mediaWays.net. [77.7.25.204]) by mx.google.com with ESMTPSA id k7sm18383144eeg.13.2013.11.08.11.44.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 08 Nov 2013 11:44:43 -0800 (PST) Message-ID: <527D3F2A.6060504@gmail.com> Date: Fri, 08 Nov 2013 20:44:42 +0100 From: Michael Schmidt User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: How to script inserts where id is needed as fk Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Hi guys, i need to script some insert statements. To simplify it a little bit so assume i got a table "User" and a table called "Article". Both tables have an serial id column. In "Articles" there is a column i need to fill with the user id lets call it "create_user_id". I want to do something like: Insert into User (name) values ('User1'); Insert into Article ('create_user_id') values (1); Insert into Article ('create_user_id') values (1); Insert into User (name) values ('User2'); Insert into Article ('create_user_id') values (2); Insert into Article ('create_user_id') values (2); So you see i have set it to 1 and 2 this not good cause it might not be 1 and 2. I probably need the id returned by the "insert into User" query to use it for the "insert into Article" query. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql