Skip site navigation (1) Skip section navigation (2)

Re: Alter column to type serial

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Thom Brown <thom(at)linux(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Alter column to type serial
Date: 2010-11-04 16:13:04
Message-ID: 1288887115-sup-2736@alvh.no-ip.org (view raw or flat)
Thread:
Lists: pgsql-hackers
Excerpts from Thom Brown's message of jue nov 04 09:05:01 -0300 2010:

> This would be instead of having to do:
> 
> CREATE SEQUENCE id_stuff_seq;
> 
> SELECT setval('id_stuff_seq', (SELECT max(id) FROM stuff))
> 
> ALTER TABLE stuff ALTER COLUMN id SET DEFAULT
> nextval('id_stuff_seq'::regclass);
> 
> Which would also mean the sequence would not get dropped with the table.

You can fix that with an ALTER SEQUENCE OWNED BY.

> Abhorrent idea, or acceptable?

I think the problem is in locking the table against futher insertions
while you do the setval.

-- 
Álvaro Herrera <alvherre(at)commandprompt(dot)com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

In response to

pgsql-hackers by date

Next:From: Daniele VarrazzoDate: 2010-11-04 16:46:28
Subject: Re: psycopg and two phase commit
Previous:From: Alvaro HerreraDate: 2010-11-04 15:50:51
Subject: Re: ALTER OBJECT any_name SET SCHEMA name

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group