Search Postgresql Archives

Re: adding columns with defaults is not implemented

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Marcelo wrote:
Hi,
Thanks for your reply, but I have some doubts.

Are yoy sugesting I create the column as an Integer then change it to
Serial? in Pgsql 7 you cant change a column type.

Serial is not a real data type. Do this.

create table foo (bar integer not null);
create sequence foo_bar_seq;
alter table foo alter column bar set default nextval('foo_bar_seq');

Sincerely,

Joshua D. Drake



If I create the column as an int then add a default value, how can I make
this default value increment with each insert?

Thanks again for your help.
Marcelo


----- Original Message ----- From: "Scott Marlowe" <smarlowe@xxxxxxxxxxxxxxxxx>
To: "Marcelo" <marcelo@xxxxxxxxxxx>
Cc: <pgsql-general@xxxxxxxxxxxxxx>
Sent: Thursday, June 02, 2005 4:43 PM
Subject: Re:  adding columns with defaults is not implemented



On Thu, 2005-06-02 at 15:29, Marcelo wrote:

Hello,
Using Postgres 7.4, I am trying to perform an "alter table
temptable add column "myCol" serial"

It gives the following msg
ERROR:  adding columns with defaults is not implemented

You cannot add a column that is serial in a table which already has
data in postgres 7.

Is there a way I can create a serial column on a table which already
has data? Or is the only solution upgrading to postgres 8 ?

You can add a default after you add the column with a separate alter
table statement...

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
   (send "unregister YourEmailAddressHere" to majordomo@xxxxxxxxxxxxxx)



---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
      subscribe-nomail command to majordomo@xxxxxxxxxxxxxx so that your
      message can get through to the mailing list cleanly


--
Your PostgreSQL solutions company - Command Prompt, Inc. 1.800.492.2240
PostgreSQL Replication, Consulting, Custom Programming, 24x7 support
Managed Services, Shared and Dedicated Hosting
Co-Authors: plPHP, plPerlNG - http://www.commandprompt.com/

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

              http://www.postgresql.org/docs/faq

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux