| From: | Richard Huxton <dev(at)archonet(dot)com> |
|---|---|
| To: | HHB <hubaghdadi(at)yahoo(dot)ca> |
| Cc: | pgsql-general(at)postgresql(dot)org |
| Subject: | Re: Using sequences in SQL text files |
| Date: | 2008-02-19 15:55:14 |
| Message-ID: | 47BAFBE2.4070407@archonet.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
HHB wrote:
> Hi.
> I have sequence for each table in my database.
> In order to populate same data in the database, I created some SQL text
> files.
> ---
> insert into categories values (id value from sequence, '..', '...');
> insert into books values (id value from sequence, '..', '...', '..', fk to
> category id);
If they are of SERIAL type then they'll use their sequence by default:
INSERT INTO my_table (id, a, b) VALUES (DEFAULT, 'abc', 123);
Otherwise you can use the currval/nextval() functions:
INSERT INTO my_table (id, a, b) VALUES (nextval(<SEQUENCE-NAME>), 'abc',
123);
--
Richard Huxton
Archonet Ltd
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2008-02-19 16:07:07 | Re: Analogue to SQL Server UniqueIdentifier? |
| Previous Message | Lone Wolf | 2008-02-19 15:54:29 | Re: Using sequences in SQL text files |