From: Jean-David Beyer <jeandavid8@verizon.net>
To: pgsql-sql@postgresql.org
Subject: Re: How to use serial variable to insert into muiti-recrods?
Date: Thu, 06 Sep 2007 07:45:41 -0400
Message-ID: <46DFE865.7040104@verizon.net> (raw)
In-Reply-To: <BAY102-F21BF5CEECBDF3E1F70C90CF0C40@phx.gbl>
References: <BAY102-F21BF5CEECBDF3E1F70C90CF0C40@phx.gbl>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
hu js wrote:
> run:
> "CREATE TABLE xxx ( id serial NOT NULL, name character varying );
> insert into xxx select default values,place_name from air_bui;"
>
> fail: "ERROR: syntax error at or near "default" SQL state: 42601
> Character: 24"
>
> How can I do?
>
It is not clear what you are trying to do. Your Subject line does not quite
agree with the text.
1.) Are you trying to use the same serial number in multiple records
(tuples)? That is what I would infer from your Subject line. If so, and if
id is the primary key, then those multiple tuples better in different tables
(relations).
2.) Are you trying to use a different serial number in each tuple you
insert? That is what your example seems to show.
In either case, I assume there is more than one column (attribute) in each
tuple. So in case 2 you might wish to declare and operate thus:
CREATE TABLE xxx
id serial NOT NULL,
name character varying
);
INSERT INTO xxx (name)
SELECT place_name
FROM air_bui
WHERE ... ;
If you are trying to use the same serial number in multiple records,
then you should get the serial number direct from the SEQUENCE and plug it
in each tuple as you need it.
- --
.~. Jean-David Beyer Registered Linux User 85642.
/V\ PGP-Key: 9A2FC99A Registered Machine 241939.
/( )\ Shrewsbury, New Jersey http://counter.li.org
^^-^^ 07:20:01 up 28 days, 10:42, 4 users, load average: 5.23, 5.18, 4.78
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with CentOS - http://enigmail.mozdev.org
iD8DBQFG3+hkPtu2XpovyZoRAvYaAJ0VRP5u3BXhihtoM60PPeh819hjGgCbB4j8
99RzX9EobFUU4u7d9qk2QKI=
=YcQX
-----END PGP SIGNATURE-----
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: jeandavid8@verizon.net
Subject: Re: How to use serial variable to insert into muiti-recrods?
In-Reply-To: <46DFE865.7040104@verizon.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox