Change column type from int to bigint - quickest way

From: Andreas Brandl <mail(at)andreas-brandl(dot)de>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Change column type from int to bigint - quickest way
Date: 2016-11-11 15:30:50
Message-ID: 946724975.6533.1478878250759.JavaMail.zimbra@andreas-brandl.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 to bigint 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andreas Brandl 2016-11-11 15:34:08 Change column type from int to bigint - quickest way
Previous Message Adrian Klaver 2016-11-11 15:14:09 Re: row => text => row