Skip site navigation (1) Skip section navigation (2)

Re: multiple inserts

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Oren Mazor" <oren(dot)mazor(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: multiple inserts
Date: 2005-06-17 14:25:28
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
"Oren Mazor" <oren(dot)mazor(at)gmail(dot)com> writes:
> I'm wondering if it is at all possible to do a mass insert into a table  
> using only a single query?
> Something along the lines of:
> insert into mytable values (val1), (val2), (val3)

We should have that (it's in the SQL spec) but no one's gotten around to
it.  You could fake it with

	insert into mytable
		select val1
		union all
		select val2
		union all

But if you are thinking of really large amounts of data (like more than
a few dozen rows), you really want to use COPY instead.  Neither the
union approach nor the still-unwritten multi-insert would be likely to
be pleasant to use for thousands/millions of rows.

			regards, tom lane

In response to


pgsql-novice by date

Next:From: Oren MazorDate: 2005-06-17 14:31:12
Subject: Re: multiple inserts
Previous:From: Mark J. BaileyDate: 2005-06-17 14:04:32
Subject: Storing an array to Postgresql table

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group