From: mike@if-then-else.pl
To: grandebuzon@gmail.com
Cc: pgsql-sql@postgresql.org
Subject: Re: The best option to insert data with primary id
Date: Mon, 06 Dec 2010 16:27:25 +0100
Message-ID: <20101206162725.o3q9xfug2ioo08g8@horde.iq.pl> (raw)
In-Reply-To: <AANLkTint7hvf03OXc8ujqWE+a2ETWUXu7NtHysKqZjUG@mail.gmail.com>
References: <AANLkTint7hvf03OXc8ujqWE+a2ETWUXu7NtHysKqZjUG@mail.gmail.com>
Quoting - <grandebuzon@gmail.com>:
> I have a question about how best to insert and manipulate the table with
> primary key id for better productivity. I need to insert data into the table
> and get last id.
>
> 1. First option to take counter Postgres SEQUENCE:
> INSERT INTO table (id, ...) VALUES ((SELECT nextval ('seq_table')), ...)
> RETURNING (SELECT currval ('seq_table')) AS id
Much simplier:
INSERT INTO table (name, email, salary) VALUES ('joe', 'joe@example.com',
100) RETURNING id;
Cheers,
-Mike
--
MichaĆ Roszka
mike@if-then-else.pl
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: mike@if-then-else.pl, grandebuzon@gmail.com
Subject: Re: The best option to insert data with primary id
In-Reply-To: <20101206162725.o3q9xfug2ioo08g8@horde.iq.pl>
* 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