Search Postgresql Archives

Re: Using sequences in SQL text files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
      choose an index scan if your joining column's datatypes do not
      match

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux