Re: SQL INSERT Statement -- Multi-Row Insert

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Alan Searles <alien(at)attglobal(dot)net>, pgsql-novice(at)postgresql(dot)org
Subject: Re: SQL INSERT Statement -- Multi-Row Insert
Date: 2003-06-14 17:11:23
Message-ID: 20030614171123.GA31163@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I made a mistake in my advice. I use just "union" for small examples done
by hand, but when doing it for programattically generated SQL you want
to use "union all". "union all" doesn't remove duplicates and doesn't
waste effort checking for duplicates. So you really want something like:

INSERT INTO table ( col1, col2, col3 )
select value1, value2, value3 union all
select value4, value5, value6 union all
select value7, value8, value9;

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2003-06-14 17:27:28 Re: SQL INSERT Statement -- Multi-Row Insert
Previous Message Bruno Wolff III 2003-06-14 14:11:17 Re: SQL INSERT Statement -- Multi-Row Insert