Thread: Altering table error

Altering table error

From
Josep Sànchez i Mesegué
Date:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'm trying to alter an existing table, whith data in it, adding a column
called "cap_id" that should be a "serial" or "serial8" type, but when I
try to do it I receive the next message:

| provesmasis-# provesmasis=# alter table captrajectes add column cap_id
serial;
| NOTICE:  ALTER TABLE will create implicit sequence
'captrajectes_cap_id_seq' for SERIAL column 'captrajectes.cap_id'
| NOTICE:  ALTER TABLE / ADD UNIQUE will create implicit index
'captrajectes_cap_id_key' for table 'captrajectes'
| ERROR:  parser: parse error at or near "notice"
| provesmasis=# NOTICE:  ALTER TABLE will create implicit sequence
'captrajectes_cap_id_seq' for SERIAL column 'captrajectes.cap_id'
| provesmasis-# NOTICE:  ALTER TABLE / ADD UNIQUE will create implicit
index 'captrajectes_cap_id_key' for table 'captrajectes'
| provesmasis-# ERROR:  Adding columns with defaults is not implemented.
| provesmasis-#         Add the column, then use ALTER TABLE SET DEFAULT.

What am I doing wrong?

Thanks in advance for your answer.

Josep Sànchez
~ [papapep]

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE+yKdP2vx52x0kyz4RAur2AJ9eIeWADsUJcB2E7jTgNA0fr/qQBACfevpE
zdKjuFf2YB4K+x1S7LdYC2c=
=HAAd
-----END PGP SIGNATURE-----




Re: Altering table error

From
Nabil Sayegh
Date:
Am Mon, 2003-05-19 um 11.43 schrieb Josep Sànchez i Mesegué:
> | provesmasis-# ERROR:  Adding columns with defaults is not implemented.
> | provesmasis-#         Add the column, then use ALTER TABLE SET DEFAULT.
>
> What am I doing wrong?

serial is a 'macro'
It is an integer with an auto-increment value.
The auto-increment is implemented as a
default nextval('HERE_COMES_A_SEQUENCE_seq'::text)

But: Alter table with defaults is not implemented.

So you have to
1. add an int column cap_id (instead of serial).
2. create a sequence
3. alter the table again and SET DEFAULT nextval('YOUR_SEQ_seq'::text);

BTW: What version of postgresql are you using ?

HTH
--
 e-Trolley Sayegh & John, Nabil Sayegh
 Tel.: 0700 etrolley /// 0700 38765539
 Fax.: +49 69 8299381-8
 PGP : www.e-trolley.de


Re: Altering table error

From
papapep
Date:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Nabil Sayegh wrote:
| BTW: What version of postgresql are you using ?

Version 7.2.1

Josep Sànchez
~ [papapep]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE+0kIq2vx52x0kyz4RAuFmAJ4kFA7fNWn0FAbbePJ8afY8yzVQngCgipPm
pU8bNtzE6DkW0GM21DynTqA=
=V+Lf
-----END PGP SIGNATURE-----