multiple row insertion

Started by test testerover 18 years ago8 messagesgeneral
Jump to latest
#1test tester
test896@gmail.com

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?

#2Mikko Partio
mpartio@gmail.com
In reply to: test tester (#1)
Re: multiple row insertion

On 10/4/07, test tester <test896@gmail.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

#3Ashish Karalkar
ashish.karalkar@info-spectrum.com
In reply to: test tester (#1)
Re: multiple row insertion

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@postgresql.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

#4test tester
test896@gmail.com
In reply to: test tester (#1)
Re: multiple row insertion
Show quoted text

On 10/4/07, test tester <test896@gmail.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.karalkar@info-spectrum.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@gmail.com>
*To:* pgsql-general@postgresql.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

#5Dawid Kuroczko
qnex42@gmail.com
In reply to: test tester (#4)
Re: multiple row insertion

On 10/4/07, test tester <test896@gmail.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?

#6A. Kretschmer
andreas.kretschmer@schollglas.com
In reply to: test tester (#4)
Re: multiple row insertion

am Thu, dem 04.10.2007, um 18:47:01 +0500 mailte test tester folgendes:

On 10/4/07, test tester <test896@gmail.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

#7Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: test tester (#4)
Re: multiple row insertion

test tester escribi�:

On 10/4/07, test tester <test896@gmail.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.

#8André Volpato
andre.volpato@ecomtecnologia.com.br
In reply to: Alvaro Herrera (#7)
Re: multiple row insertion

<!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.GI6176@alvh.no-ip.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@gmail.com">&lt;test896@gmail.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>