pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
How to use serial variable to insert into muiti-recrods?
5+ messages / 5 participants
[nested] [flat]

* How to use serial variable to insert into muiti-recrods?
@ 2007-09-06 07:11 hu js <hu.bill2005@hotmail.com>
  2007-09-06 07:48 ` Re: How to use serial variable to insert into muiti-recrods? Ashish Karalkar <ashish.karalkar@info-spectrum.com>
  2007-09-06 07:49 ` Re: How to use serial variable to insert into muiti-recrods? Milen A. Radev <milen@radev.net>
  2007-09-06 08:16 ` Re: How to use serial variable to insert into muiti-recrods? Richard Huxton <dev@archonet.com>
  2007-09-06 11:45 ` Re: How to use serial variable to insert into muiti-recrods? Jean-David Beyer <jeandavid8@verizon.net>
  0 siblings, 4 replies; 5+ messages in thread

From: hu js @ 2007-09-06 07:11 UTC (permalink / raw)
  To: pgsql-sql

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?

Bill Gates

_________________________________________________________________
与联机的朋友进行交流,请使用 MSN Messenger:  http://messenger.msn.com/cn  




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: How to use serial variable to insert into muiti-recrods?
  2007-09-06 07:11 How to use serial variable to insert into muiti-recrods? hu js <hu.bill2005@hotmail.com>
@ 2007-09-06 07:48 ` Ashish Karalkar <ashish.karalkar@info-spectrum.com>
  3 siblings, 0 replies; 5+ messages in thread

From: Ashish Karalkar @ 2007-09-06 07:48 UTC (permalink / raw)
  To: hu js <hu.bill2005@hotmail.com>; pgsql-sql

I think default is a key  word whic u r using as a column name in select 
statment.

With Regards
Ashish...

----- Original Message ----- 
From: "hu js" <hu.bill2005@hotmail.com>
To: <pgsql-sql@postgresql.org>
Sent: Thursday, September 06, 2007 12:41 PM
Subject: [SQL] How to use serial variable to insert into muiti-recrods?


> 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?
>
> Bill Gates
>
> _________________________________________________________________
> 与联机的朋友进行交流,请使用 MSN Messenger:  http://messenger.msn.com/cn
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
>               http://www.postgresql.org/docs/faq 




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: How to use serial variable to insert into muiti-recrods?
  2007-09-06 07:11 How to use serial variable to insert into muiti-recrods? hu js <hu.bill2005@hotmail.com>
@ 2007-09-06 07:49 ` Milen A. Radev <milen@radev.net>
  3 siblings, 0 replies; 5+ messages in thread

From: Milen A. Radev @ 2007-09-06 07:49 UTC (permalink / raw)
  To: pgsql-sql

hu js написа:
> run:
> "CREATE TABLE xxx
> (
> id serial NOT NULL,
> name character varying
> );
> insert into xxx select default values,place_name from air_bui;"

insert into xxx (name) select place_name from air_bui;

> 
> fail:
> "ERROR: syntax error at or near "default"
> SQL state: 42601
> Character: 24"
> 


-- 
Milen A. Radev





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: How to use serial variable to insert into muiti-recrods?
  2007-09-06 07:11 How to use serial variable to insert into muiti-recrods? hu js <hu.bill2005@hotmail.com>
@ 2007-09-06 08:16 ` Richard Huxton <dev@archonet.com>
  3 siblings, 0 replies; 5+ messages in thread

From: Richard Huxton @ 2007-09-06 08:16 UTC (permalink / raw)
  To: hu js <hu.bill2005@hotmail.com>; +Cc: pgsql-sql

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;"

insert into xxx (name) SELECT place_name FROM ...

HTH
-- 
  Richard Huxton
  Archonet Ltd



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: How to use serial variable to insert into muiti-recrods?
  2007-09-06 07:11 How to use serial variable to insert into muiti-recrods? hu js <hu.bill2005@hotmail.com>
@ 2007-09-06 11:45 ` Jean-David Beyer <jeandavid8@verizon.net>
  3 siblings, 0 replies; 5+ messages in thread

From: Jean-David Beyer @ 2007-09-06 11:45 UTC (permalink / raw)
  To: pgsql-sql

-----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-----



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2007-09-06 11:45 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-09-06 07:11 How to use serial variable to insert into muiti-recrods? hu js <hu.bill2005@hotmail.com>
2007-09-06 07:48 ` Ashish Karalkar <ashish.karalkar@info-spectrum.com>
2007-09-06 07:49 ` Milen A. Radev <milen@radev.net>
2007-09-06 08:16 ` Richard Huxton <dev@archonet.com>
2007-09-06 11:45 ` Jean-David Beyer <jeandavid8@verizon.net>

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