Change column type from int to bigint - quickest way - Mailing list pgsql-general

From Andreas Brandl
Subject Change column type from int to bigint - quickest way
Date
Msg-id 946724975.6533.1478878250759.JavaMail.zimbra@andreas-brandl.de
Whole thread Raw
Responses Re: Change column type from int to bigint - quickest way
List pgsql-general
Hi,

we have a pretty big table with an integer-type primary key. I'm looking for the quickest way to change the column type
tobigint to avoid hitting the integer limit. We're trying to avoid prolonged lock situations and full table rewrites. 

I know I can hack this with an UPDATE on pg_attribute:

-- change id type to bigint
update pg_attribute set atttypid=20 where attrelid=264782 and attname = 'id';

After that I'd need to reflect the change on dependent objects like views as well.

Is this safe to do? Are there any unwanted consequences to this?

This is still on 9.1 unfortunately - upgrade is going to follow soon after this.

Thanks!
Andreas


pgsql-general by date:

Previous
From: Cynthia Hombakazi Ngejane
Date:
Subject: Syncing Data of data type BLOB into Postgres- Bytea
Next
From: Moreno Andreo
Date:
Subject: Re: Best practices to manage custom statistics