Re: Cannot add an column of type serial or bigserial

Lists: pgadmin-supportpgsql-hackers
From: David Sigeti <sigeti(at)lanl(dot)gov>
To: pgadmin-support(at)postgresql(dot)org
Subject: Cannot add an column of type serial or bigserial
Date: 2003-12-10 05:55:16
Message-ID: 5.1.1.5.2.20031209225310.00b09070@x-mail.lanl.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgadmin-support pgsql-hackers

Dear Pgadmin Folks,

I am using pgadminIII 1.0.2 with PostgreSQL 7.4 under W2K SP4 and Cygwin
(current as of 2 or 3 weeks ago). The server is running locally.

If I attempt to add an column of type serial or bigserial to a table, the
operation fails with a message telling me that adding an column with a
default value is not implemented. What is really weird is that one can, in
fact, add a column with a default value, like an int4 with a default value
or 0. The problem does not arise if the serial (or bigserial) column is
created when the table is created (as a part of CREATE TABLE).

Yours,
David

---
Dr. David E. Sigeti
Phone: 505-667-9239
E-mail: sigeti(at)lanl(dot)gov
Surface mail: X-8, MS-F645, Los Alamos National Laboratory,
Los Alamos, NM 87545 USA


From: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
To: David Sigeti <sigeti(at)lanl(dot)gov>
Cc: pgadmin-support(at)postgresql(dot)org
Subject: Re: Cannot add an column of type serial or bigserial
Date: 2003-12-10 06:11:19
Message-ID: 3FD6B907.9070704@familyhealth.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgadmin-support pgsql-hackers

You cannot add a serial column after table creation time in PostgreSQL.

Chris

David Sigeti wrote:

> Dear Pgadmin Folks,
>
> I am using pgadminIII 1.0.2 with PostgreSQL 7.4 under W2K SP4 and Cygwin
> (current as of 2 or 3 weeks ago). The server is running locally.
>
> If I attempt to add an column of type serial or bigserial to a table,
> the operation fails with a message telling me that adding an column with
> a default value is not implemented. What is really weird is that one
> can, in fact, add a column with a default value, like an int4 with a
> default value or 0. The problem does not arise if the serial (or
> bigserial) column is created when the table is created (as a part of
> CREATE TABLE).
>
> Yours,
> David
>
> ---
> Dr. David E. Sigeti
> Phone: 505-667-9239
> E-mail: sigeti(at)lanl(dot)gov
> Surface mail: X-8, MS-F645, Los Alamos National Laboratory,
> Los Alamos, NM 87545 USA
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org


From: Ian Freislich <ianf(at)za(dot)uu(dot)net>
To: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
Cc: David Sigeti <sigeti(at)lanl(dot)gov>, pgadmin-support(at)postgresql(dot)org
Subject: Re: Cannot add an column of type serial or bigserial
Date: 2003-12-10 07:58:56
Message-ID: 49373.1071043136@za.uu.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgadmin-support pgsql-hackers

Christopher Kings-Lynne wrote:
> You cannot add a serial column after table creation time in PostgreSQL.

But you can do the following from the query editor:

ALTER TABLE table ADD column INTEGER;
CREATE SEQUENCE table_column_seq;
ALTER TABLE table ALTER column SET DEFAULT nextval('"table_column_seq"'::text);

If you want the column to be NOT NULL as well, you will have to
populate that column for all the rows and then do:

ALTER TABLE table ALTER column SET NOT NULL;

Ian

> Chris
>
> David Sigeti wrote:
>
> > Dear Pgadmin Folks,
> >
> > I am using pgadminIII 1.0.2 with PostgreSQL 7.4 under W2K SP4 and Cygwin
> > (current as of 2 or 3 weeks ago). The server is running locally.
> >
> > If I attempt to add an column of type serial or bigserial to a table,
> > the operation fails with a message telling me that adding an column with
> > a default value is not implemented. What is really weird is that one
> > can, in fact, add a column with a default value, like an int4 with a
> > default value or 0. The problem does not arise if the serial (or
> > bigserial) column is created when the table is created (as a part of
> > CREATE TABLE).
> >
> > Yours,
> > David
> >
> > ---
> > Dr. David E. Sigeti
> > Phone: 505-667-9239
> > E-mail: sigeti(at)lanl(dot)gov
> > Surface mail: X-8, MS-F645, Los Alamos National Laboratory,
> > Los Alamos, NM 87545 USA
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 6: Have you searched our list archives?
> >
> > http://archives.postgresql.org
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
>


From: Andreas Pflug <pgadmin(at)pse-consulting(dot)de>
To: David Sigeti <sigeti(at)lanl(dot)gov>
Cc: pgadmin-support(at)postgresql(dot)org
Subject: Re: Cannot add an column of type serial or bigserial
Date: 2003-12-10 11:21:15
Message-ID: 3FD701AB.7060901@pse-consulting.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgadmin-support pgsql-hackers

David Sigeti wrote:

> Dear Pgadmin Folks,
>
> I am using pgadminIII 1.0.2 with PostgreSQL 7.4 under W2K SP4 and
> Cygwin (current as of 2 or 3 weeks ago). The server is running locally.
>
> If I attempt to add an column of type serial or bigserial to a table,
> the operation fails with a message telling me that adding an column
> with a default value is not implemented. What is really weird is that
> one can, in fact, add a column with a default value, like an int4 with
> a default value or 0. The problem does not arise if the serial (or
> bigserial) column is created when the table is created (as a part of
> CREATE TABLE).
>
serial isn't a true datatype but a keyword that can be used only at
creation time. Still, pgAdmin3 should create the commands necessary for
this to make life easier; I added this as a TODO item.

Regards,
Andreas


From: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
To: Andreas Pflug <pgadmin(at)pse-consulting(dot)de>
Cc: David Sigeti <sigeti(at)lanl(dot)gov>, pgadmin-support(at)postgresql(dot)org
Subject: Re: Cannot add an column of type serial or bigserial
Date: 2003-12-10 11:40:48
Message-ID: 3FD70640.7070700@familyhealth.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgadmin-support pgsql-hackers

> serial isn't a true datatype but a keyword that can be used only at
> creation time. Still, pgAdmin3 should create the commands necessary for
> this to make life easier; I added this as a TODO item.

The problem will be recording the dependency properly in pg_depend...

Chris


From: Andreas Pflug <pgadmin(at)pse-consulting(dot)de>
To: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
Cc: David Sigeti <sigeti(at)lanl(dot)gov>, pgadmin-support(at)postgresql(dot)org
Subject: Re: Cannot add an column of type serial or bigserial
Date: 2003-12-10 13:34:48
Message-ID: 3FD720F8.2040006@pse-consulting.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgadmin-support pgsql-hackers

Christopher Kings-Lynne wrote:

>> serial isn't a true datatype but a keyword that can be used only at
>> creation time. Still, pgAdmin3 should create the commands necessary
>> for this to make life easier; I added this as a TODO item.
>
>
> The problem will be recording the dependency properly in pg_depend...

That's no real problem, just an issue that should be thought of; thanks
for mentioning.

Regards,
Andreas


From: David Sigeti <sigeti(at)lanl(dot)gov>
To: pgadmin-support(at)postgresql(dot)org
Subject: Re: Cannot add an column of type serial or
Date: 2003-12-10 15:54:46
Message-ID: 5.1.1.5.2.20031210084752.00aaaf98@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgadmin-support pgsql-hackers

At 12:21 PM 12/10/2003 +0100, Andreas Pflug wrote:

>David Sigeti wrote:
>
>>I am using pgadminIII 1.0.2 with PostgreSQL 7.4 under W2K SP4 and Cygwin
>>(current as of 2 or 3 weeks ago). The server is running locally.
>>
>>If I attempt to add an column of type serial or bigserial to a table, the
>>operation fails with a message telling me that adding an column with a
>>default value is not implemented. What is really weird is that one can,
>>in fact, add a column with a default value, like an int4 with a default
>>value or 0. The problem does not arise if the serial (or bigserial)
>>column is created when the table is created (as a part of CREATE TABLE).
>serial isn't a true datatype but a keyword that can be used only at
>creation time. Still, pgAdmin3 should create the commands necessary for
>this to make life easier; I added this as a TODO item.

Adding this functionality would be great but I suggest that the error
message be changed right away as it is seriously misleading.

Thanks to everyone who took the time to help me out.

Yours,
David

---
Dr. David E. Sigeti
Phone: 505-667-9239
E-mail: sigeti(at)lanl(dot)gov
Surface mail: X-8, MS-F645, Los Alamos National Laboratory,
Los Alamos, NM 87545 USA


From: Andreas Pflug <pgadmin(at)pse-consulting(dot)de>
To: David Sigeti <sigeti(at)lanl(dot)gov>
Cc: pgadmin-support(at)postgresql(dot)org, PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Cannot add an column of type serial
Date: 2003-12-10 16:13:35
Message-ID: 3FD7462F.40808@pse-consulting.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgadmin-support pgsql-hackers

David Sigeti wrote:

> At 12:21 PM 12/10/2003 +0100, Andreas Pflug wrote:
>
>> David Sigeti wrote:
>>
>>> I am using pgadminIII 1.0.2 with PostgreSQL 7.4 under W2K SP4 and
>>> Cygwin (current as of 2 or 3 weeks ago). The server is running
>>> locally.
>>>
>>> If I attempt to add an column of type serial or bigserial to a
>>> table, the operation fails with a message telling me that adding an
>>> column with a default value is not implemented. What is really
>>> weird is that one can, in fact, add a column with a default value,
>>> like an int4 with a default value or 0.
>>
pgAdmin breaks this into two steps for you; have a look at the SQL page.

>>> The problem does not arise if the serial (or bigserial) column is
>>> created when the table is created (as a part of CREATE TABLE).
>>
>> serial isn't a true datatype but a keyword that can be used only at
>> creation time. Still, pgAdmin3 should create the commands necessary
>> for this to make life easier; I added this as a TODO item.
>
>
> Adding this functionality would be great but I suggest that the error
> message be changed right away as it is seriously misleading.
>
The error message originates from the backend. I agree that this might
be confusing to newbies, who don't know that serial actually is int4
default nextval('...') (currently pgAdmin3 doesn't either :-)

I'm forwarding this to pgsql-hackers.

Regards,
Andreas