Re: multiple row insertion

Lists: pgsql-general
From: "test tester" <test896(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: multiple row insertion
Date: 2007-10-04 11:19:58
Message-ID: 4640d9b40710040419m579d52f7gaf73d3fe1a6450de@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

In MySQL, I can insert multiple rows like this:

insert into cars values(5, "toyota"),(5,"ford"), etc.

How can I do something similiar in PostgreSQL?


From: "Mikko Partio" <mpartio(at)gmail(dot)com>
To: "test tester" <test896(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: multiple row insertion
Date: 2007-10-04 11:34:41
Message-ID: 2ca799770710040434l296b5a95o7e62354c3485d5a8@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On 10/4/07, test tester <test896(at)gmail(dot)com> wrote:
>
> In MySQL, I can insert multiple rows like this:
>
>
> insert into cars values(5, "toyota"),(5,"ford"), etc.
>
>
> How can I do something similiar in PostgreSQL?
>
>
Exactly the same way. Make sure though that your pgsql is new enough version
(8.2 ?).

Regards

MP


From: "Ashish Karalkar" <ashish(dot)karalkar(at)info-spectrum(dot)com>
To: "test tester" <test896(at)gmail(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: multiple row insertion
Date: 2007-10-04 11:42:33
Message-ID: 00e601c8067b$ab189c40$170211ac@LIONKING.COM
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

INSERT INTO qsweb.core_board(board_name, entry_user_id, entry_date)
VALUES ('a',1,now()),('b',1,now());
----- Original Message -----
From: test tester
To: pgsql-general(at)postgresql(dot)org
Sent: Thursday, October 04, 2007 4:49 PM
Subject: [GENERAL] multiple row insertion

In MySQL, I can insert multiple rows like this:

insert into cars values(5, "toyota"),(5,"ford"), etc.
How can I do something similiar in PostgreSQL?

insert into cars (id,name) values (1,'toyota'),(2,'ford');

With Regards
Ashish


From: "test tester" <test896(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: multiple row insertion
Date: 2007-10-04 13:47:01
Message-ID: 4640d9b40710040647q6693cb41qefcd6da7f3312d49@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On 10/4/07, test tester <test896(at)gmail(dot)com> wrote:
>
> i have version 8.1 and i want to know how to insert multiple rows in this
> version.
>
> On 10/4/07, Ashish Karalkar < ashish(dot)karalkar(at)info-spectrum(dot)com> wrote:
> >
> > INSERT INTO qsweb.core_board(board_name, entry_user_id, entry_date)
> > VALUES ('a',1,now()),('b',1,now());
> >
> > ----- Original Message -----
> > *From:* test tester <test896(at)gmail(dot)com>
> > *To:* pgsql-general(at)postgresql(dot)org
> > *Sent:* Thursday, October 04, 2007 4:49 PM
> > *Subject:* [GENERAL] multiple row insertion
> >
> > In MySQL, I can insert multiple rows like this:
> >
> >
> > insert into cars values(5, "toyota"),(5,"ford"), etc.
> >
> >
> > How can I do something similiar in PostgreSQL?
> >
> >
> > insert into cars (id,name) values (1,'toyota'),(2,'ford');
> >
> > With Regards
> > Ashish
> >
> >
>


From: "Dawid Kuroczko" <qnex42(at)gmail(dot)com>
To: "test tester" <test896(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: multiple row insertion
Date: 2007-10-04 14:02:55
Message-ID: 758d5e7f0710040702n19c9a57ahe93394820a80c074@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

> On 10/4/07, test tester <test896(at)gmail(dot)com> wrote:
> > i have version 8.1 and i want to know how to insert multiple rows in this
> version.

Please don't top post.

If you need this functionality, you should really upgrade.

In cases where you want to insert multiple rows in version 8.1, you
could use COPY command:
http://www.postgresql.org/docs/8.1/interactive/sql-copy.html

You use it like this:
COPY cars FROM STDIN DELIMITER AS ',' CSV;
5,toyota
6,ford
\.

Or if you really need to use INSERT you could use such construct:

INSERT INTO cars SELECT 5, 'toyota' UNION ALL SELECT 6, 'ford'
UNION ALL SELECT 7, 'bmw';

In short: really get the 8.2 version. 8.2 is compatible with earlier
versions and will be coming soon.

Regards,
Dawid
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?


From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: multiple row insertion
Date: 2007-10-04 14:15:02
Message-ID: 20071004141502.GI15428@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

am Thu, dem 04.10.2007, um 18:47:01 +0500 mailte test tester folgendes:
>
>
> On 10/4/07, test tester <test896(at)gmail(dot)com> wrote:
>
> i have version 8.1 and i want to know how to insert multiple rows in this
> version.

Please no silly top post.

You can insert multiple values with one insert with multiple select and
UNION like this example:

test=*# truncate foo;
TRUNCATE TABLE
test=*# select * from foo;
w
---
(0 rows)

test=*# insert into foo select 'foo1' union select 'foo2' union select 'foo3';
INSERT 0 3
test=*# select * from foo;
w
------
foo1
foo2
foo3
(3 rows)

Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net


From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: test tester <test896(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: multiple row insertion
Date: 2007-10-04 14:23:01
Message-ID: 20071004142301.GI6176@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

test tester escribió:
> On 10/4/07, test tester <test896(at)gmail(dot)com> wrote:
>
> > i have version 8.1 and i want to know how to insert multiple rows in this
> > version.

Upgrade.

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.


From: André Volpato <andre(dot)volpato(at)ecomtecnologia(dot)com(dot)br>
To: pgsql-general(at)postgresql(dot)org
Cc: test tester <test896(at)gmail(dot)com>
Subject: Re: multiple row insertion
Date: 2007-10-04 14:34:58
Message-ID: 4704FA12.3040605@ecomtecnologia.com.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Alvaro Herrera escreveu:
<blockquote cite="mid:20071004142301(dot)GI6176(at)alvh(dot)no-ip(dot)org" type="cite">
<pre wrap="">test tester escribi&oacute;:
</pre>
<blockquote type="cite">
<pre wrap="">On 10/4/07, test tester <a class="moz-txt-link-rfc2396E" href="mailto:test896(at)gmail(dot)com">&lt;test896(at)gmail(dot)com&gt;</a> wrote:

</pre>
<blockquote type="cite">
<pre wrap="">i have version 8.1 and i want to know how to insert multiple rows in this
version.
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->
Upgrade.

</pre>
</blockquote>
Use COPY instead.<br>
<br>
Put you data into a var, and perform a COPY from STDIN.<br>
<br>
[]&acute;s<br>
ACV<br>
</body>
</html>

Attachment Content-Type Size
unknown_filename text/html 917 bytes