[SQL] How to use serial variable to insert into muiti-recrods?

2007-09-06 Thread hu js

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


Re: [SQL] How to use serial variable to insert into muiti-recrods?

2007-09-06 Thread Ashish Karalkar
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" <[EMAIL PROTECTED]>

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


Re: [SQL] How to use serial variable to insert into muiti-recrods?

2007-09-06 Thread Milen A. Radev
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


Re: [SQL] How to use serial variable to insert into muiti-recrods?

2007-09-06 Thread Richard Huxton
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


Re: [SQL] How to use serial variable to insert into muiti-recrods?

2007-09-06 Thread Jean-David Beyer
-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,
namecharacter 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 Jerseyhttp://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-

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


[SQL] to_date function

2007-09-06 Thread anru chen
Hi all:

i am use postgres 8.2 on windows XP, following select statement

"select to_date('10 August 2007','DD Month ');"
return me 0007-08-10,

if i do "select to_date('10 September 2007','DD Month ');"
result is correct 2007-09-10

seems like "to_date" function only work correctly for current month.

 any one know why?

regards,

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


Re: [SQL] to_date function

2007-09-06 Thread A. Kretschmer
am  Fri, dem 07.09.2007, um 17:22:30 +1200 mailte anru chen folgendes:
> Hi all:
> 
> i am use postgres 8.2 on windows XP, following select statement
> 
> "select to_date('10 August 2007','DD Month ');"
> return me 0007-08-10,
> 
> if i do "select to_date('10 September 2007','DD Month ');"
> result is correct 2007-09-10
> 
> seems like "to_date" function only work correctly for current month.

No, seems like to_char only work corrently if the length of the month
correctly...

test=*# select to_date('10 August2007','DD Month ');
  to_date

 2007-08-10
(1 row)

test=*# select to_date('10 August   2007','DD Month ');
  to_date

 0007-08-10
(1 row)



But this is described, see:
http://www.postgresql.org/docs/current/static/functions-formatting.html

,[  quote  ]
| MONTH full uppercase month name (blank-padded to 9 chars)
| Month full mixed-case month name (blank-padded to 9 chars)
| month full lowercase month name (blank-padded to 9 chars)
`



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

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


Re: [SQL] to_date function

2007-09-06 Thread Phillip Smith
-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of anru chen
Sent: Friday, 7 September 2007 15:23
To: pgsql-sql@postgresql.org
Subject: [SQL] to_date function

> Hi all:
>
> i am use postgres 8.2 on windows XP, following select statement
>
> "select to_date('10 August 2007','DD Month ');"
> return me 0007-08-10,
>
> if i do "select to_date('10 September 2007','DD Month ');"
> result is correct 2007-09-10

Try using TO_CHAR instead of TO_DATE if it's just for display purposes (I
assume it is)

If it's for comparison purposes, then just cast to a date either by CAST('10
August 2007' AS date) or '10 August 2007'::DATE

~p


THINK BEFORE YOU PRINT - Save paper if you don't really need to print this

***Confidentiality and Privilege Notice***

The material contained in this message is privileged and confidential to
the addressee.  If you are not the addressee indicated in this message or
responsible for delivery of the message to such person, you may not copy
or deliver this message to anyone, and you should destroy it and kindly
notify the sender by reply email.

Information in this message that does not relate to the official business
of Weatherbeeta must be treated as neither given nor endorsed by Weatherbeeta.
Weatherbeeta, its employees, contractors or associates shall not be liable
for direct, indirect or consequential loss arising from transmission of this
message or any attachments
e-mail.

---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
   subscribe-nomail command to [EMAIL PROTECTED] so that your
   message can get through to the mailing list cleanly