Re: Multiple Inserts

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: operationsengineer1(at)yahoo(dot)com
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Multiple Inserts
Date: 2005-07-22 21:09:57
Message-ID: 20050722210957.GA20441@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Fri, Jul 22, 2005 at 01:49:25PM -0700, operationsengineer1(at)yahoo(dot)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/

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message operationsengineer1 2005-07-22 21:22:58 Re: Multiple Inserts
Previous Message operationsengineer1 2005-07-22 20:49:25 Multiple Inserts