From: | Rick Gigger <rick(at)alpinenetworking(dot)com> |
---|---|
To: | Chris <dmagick(at)gmail(dot)com> |
Cc: | Gonzalo Villegas <chalo1970(at)hotmail(dot)com>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Insert more than one t-uple in a single sql |
Date: | 2006-02-09 23:29:26 |
Message-ID: | 888D331E-3142-4CC0-827C-B8F1E5D14248@alpinenetworking.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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(at)postgresql(dot)org so that
> your
> message can get through to the mailing list cleanly
>
From | Date | Subject | |
---|---|---|---|
Next Message | David Rio Deiros | 2006-02-09 23:33:09 | distinct not working in a multiple join |
Previous Message | Klint Gore | 2006-02-09 23:26:06 | Re: Insert more than one t-uple in a single sql |