Unix Technical Forum

How to use serial variable to insert into muiti-recrods?

This is a discussion on How to use serial variable to insert into muiti-recrods? within the pgsql Sql forums, part of the PostgreSQL category; --> run: "CREATE TABLE xxx ( id serial NOT NULL, name character varying ); insert into xxx select default values,place_name ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Sql

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008, 05:53 PM
hu js
 
Posts: n/a
Default 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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-19-2008, 05:53 PM
Ashish Karalkar
 
Posts: n/a
Default Re: How to use serial variable to insert into muiti-recrods?

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



---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-19-2008, 05:53 PM
Milen A. Radev
 
Posts: n/a
Default Re: How to use serial variable to insert into muiti-recrods?

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



---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-19-2008, 05:53 PM
Richard Huxton
 
Posts: n/a
Default Re: How to use serial variable to insert into muiti-recrods?

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

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-19-2008, 05:53 PM
Jean-David Beyer
 
Posts: n/a
Default Re: How to use serial variable to insert into muiti-recrods?

-----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+hkPtu2XpovyZoRAvYaAJ0VRP5u3BXhihtoM60PPe h819hjGgCbB4j8
99RzX9EobFUU4u7d9qk2QKI=
=YcQX
-----END PGP SIGNATURE-----

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:08 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com