pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Alter column / array
5+ messages / 3 participants
[nested] [flat]

* Alter column / array
@ 2001-10-11 07:12  Rolf Lüttecke <rolf.luettecke@michael-telecom.de>
  0 siblings, 2 replies; 5+ messages in thread

From: Rolf Lüttecke @ 2001-10-11 07:12 UTC (permalink / raw)
  To: pgsql-admin

Hi list,

I can't find out why the following command give different results:

database-# CREATE TABLE "test1" (dev_id int, dev_slots integer[] DEFAULT
'{0,0,0,0,0}');
CREATE

If you display (\d test1) the table-structure all looks good - even the
DEFAULTs.

...but if you have an existing table and want to add a column of type array,
it doesn't
work:

database-# CREATE TABLE "test2" (dev_id int);
CREATE
database-# ALTER TABLE "test2" ADD COLUMN dev_slots integer[] DEFAULT
'{0,0,0,0,0}');
ALTER

If you now display the table-structure, the DEFAULT-statement is not listed
and
UPDATE-commands on the ARRAY do strange things.

Any clou?

Regards
R. Lüttecke (IT)

MICHAELTELECOM AG
Bruchheide 34
49163 Bohmte
+49 5471 8060
http://www.michael-telecom.de




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Alter column / array
@ 2001-10-11 16:37  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Rolf Lüttecke <rolf.luettecke@michael-telecom.de>
  1 sibling, 1 reply; 5+ messages in thread

From: Tom Lane @ 2001-10-11 16:37 UTC (permalink / raw)
  To: Rolf Lüttecke <rolf.luettecke@michael-telecom.de>; +Cc: pgsql-admin

=?iso-8859-1?Q?Rolf_L=FCttecke?= <rolf.luettecke@michael-telecom.de> writes:
> I can't find out why the following command give different results:

ALTER TABLE ADD COLUMN doesn't support adding a default.  (There is a
test in the code that's supposed to kick out an error message telling
you so, but it doesn't seem to be working.  Need to look at that.)

You can use ALTER TABLE SET DEFAULT to add the default after you add
the column.

Hmm ... I wonder why ADD COLUMN doesn't just call the SET DEFAULT
routine to handle adding the default ...

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Alter column / array
@ 2001-10-11 18:07  Stephan Szabo <sszabo@megazone23.bigpanda.com>
  parent: Rolf Lüttecke <rolf.luettecke@michael-telecom.de>
  1 sibling, 0 replies; 5+ messages in thread

From: Stephan Szabo @ 2001-10-11 18:07 UTC (permalink / raw)
  To: Rolf Lüttecke <rolf.luettecke@michael-telecom.de>; +Cc: pgsql-admin

On Thu, 11 Oct 2001, [iso-8859-1] Rolf Lüttecke wrote:

> Hi list,
> 
> I can't find out why the following command give different results:
> 
> database-# CREATE TABLE "test1" (dev_id int, dev_slots integer[] DEFAULT
> '{0,0,0,0,0}');
> CREATE
> 
> If you display (\d test1) the table-structure all looks good - even the
> DEFAULTs.
> 
> ...but if you have an existing table and want to add a column of type array,
> it doesn't
> work:
> 
> database-# CREATE TABLE "test2" (dev_id int);
> CREATE
> database-# ALTER TABLE "test2" ADD COLUMN dev_slots integer[] DEFAULT
> '{0,0,0,0,0}');
> ALTER
> 
> If you now display the table-structure, the DEFAULT-statement is not listed
> and
> UPDATE-commands on the ARRAY do strange things.

If I remember correctly, defaults are currently ignored on add
column.  I think you can use alter table alter column to add the default.

And, what do you mean by updates doing strange things?




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Alter column / array
@ 2001-10-12 07:31  Rolf Lüttecke <rolf.luettecke@michael-telecom.de>
  0 siblings, 0 replies; 5+ messages in thread

From: Rolf Lüttecke @ 2001-10-12 07:31 UTC (permalink / raw)
  To: pgsql-admin

Hi Tom,

> You can use ALTER TABLE SET DEFAULT to add the default after you add
> the column.
Works.

> Hmm ... I wonder why ADD COLUMN doesn't just call the SET DEFAULT
> routine to handle adding the default ...
I'm wondering too. But all programs do only those things they were told
to do - mostly, not always ;-)

Hi Stephan,

> And, what do you mean by updates doing strange things?
Follow-up-errors caused by updating an uninitialized array. Now it is
clear why it couldn't work.

Thanx and regards

R. Lüttecke (IT)

MICHAELTELECOM AG
Bruchheide 34
49163 Bohmte
+49 5471 8060
http://www.michael-telecom.de




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Alter column / array
@ 2001-10-12 15:29  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2001-10-12 15:29 UTC (permalink / raw)
  To: Rolf Lüttecke <rolf.luettecke@michael-telecom.de>; pgsql-admin

=?iso-8859-1?Q?Rolf_L=FCttecke?= <rolf.luettecke@michael-telecom.de> writes:
>> I can't find out why the following command give different results:

> ALTER TABLE ADD COLUMN doesn't support adding a default.  (There is a
> test in the code that's supposed to kick out an error message telling
> you so, but it doesn't seem to be working.  Need to look at that.)

I've committed fixes for that problem in 7.2.

> Hmm ... I wonder why ADD COLUMN doesn't just call the SET DEFAULT
> routine to handle adding the default ...

On looking at the archives (see pgsql-hackers around 17-Jul-01),
I see that this wasn't done because it's not an SQL92-compliant
behavior.  Our current implementation of ADD COLUMN can't support
setting the new column's entries to anything except NULL, but the
spec says that if there's a DEFAULT then the column should initially
be filled with that value.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2001-10-12 15:29 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-10-11 07:12 Alter column / array Rolf Lüttecke <rolf.luettecke@michael-telecom.de>
2001-10-11 16:37 ` Tom Lane <tgl@sss.pgh.pa.us>
2001-10-12 15:29   ` Tom Lane <tgl@sss.pgh.pa.us>
2001-10-11 18:07 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
2001-10-12 07:31 Re: Alter column / array Rolf Lüttecke <rolf.luettecke@michael-telecom.de>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox