On Fri, Jul 22, 2005 at 01:49:25PM -0700, operationsengineer1@yahoo.com wrote:
>
> i need to insert multiple serial numbers at a time
> (eg, 100). my current idea is to allow the user to
> enter a beginning serial number, an ending serial
> number and then use php to iterate through the numbers
> and insert them (i'm thinking multiple inserts (get
> value -> insert, get 2nd value -> insert, get 3rd
> value, insert, etc...) unless someone can give me an
> idea how to collect the data then do one big insert).
In 8.0 you can use INSERT ... SELECT and generate_series():
http://www.postgresql.org/docs/8.0/static/sql-insert.html
http://www.postgresql.org/docs/8.0/static/functions-srf.html
Example:
INSERT INTO foo (serialnum) SELECT * FROM generate_series(1, 100);
Although older versions of PostgreSQL don't have generate_series(),
it's trivial to write with PL/pgSQL or other languages. Read up
on set-returning functions or search the archives for examples.
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/