Re: Insert more than one t-uple in a single sql - Mailing list pgsql-general

From Rick Gigger
Subject Re: Insert more than one t-uple in a single sql
Date
Msg-id 888D331E-3142-4CC0-827C-B8F1E5D14248@alpinenetworking.com
Whole thread Raw
In response to Re: Insert more than one t-uple in a single sql  (Chris <dmagick@gmail.com>)
Responses Re: Insert more than one t-uple in a single sql  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
There is a little trick you can do though, it goes something like this:

insert into table (field1, field2, field3) select v1, v2, v3 union
b1, b2, b3 union select c1, c2, c3

I originally did this because it was significantly faster on SQL
Server 2000 than doing the inserts individually.  Usually I did it
with up to maybe 20 rows at a time that were all grouped to some kind
of common parent.

Some version of postgres a long time ago broke my code because it did
some stricter type checking and so I had to make sure that I was
never putting single quotes around int and that date fields were
strictly typecasted so that it wouldn't think they were strings.  It
does work now though as long as I do that and I use it all the time.
I don't know if it gets the same sort of speed boost in postgres as
it did in sql server.  As long as they are all done within a single
transaction in postgres it may not matter whether you do them
individually or batched like that.

If you really have a lot of data you want to insert at once why not
just use COPY?

Rick


On Feb 9, 2006, at 4:13 PM, Chris wrote:

> Hi,
>
> You can't do that in postgres, sorry. That's a mysql-ism.
>
> Gonzalo Villegas wrote:
>
>> It must be something like
>> insert into table (field1,field2,...) values (v1,v2,...),(b1,b2,...),
>> (c1,c2,...)
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
>       subscribe-nomail command to majordomo@postgresql.org so that
> your
>       message can get through to the mailing list cleanly
>


pgsql-general by date:

Previous
From: Klint Gore
Date:
Subject: Re: Insert more than one t-uple in a single sql
Next
From: David Rio Deiros
Date:
Subject: distinct not working in a multiple join