One-off attempt at catalog hacking to turn bytea column into text

From: Vlad Romascanu <vromascanu(at)accurev(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: One-off attempt at catalog hacking to turn bytea column into text
Date: 2011-05-10 20:31:37
Message-ID: BANLkTimFQCKEOD_TQd1rR0jo3MTqkk36=Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

As a one-off attempt to change a large table's 'bytea' column to
'text' with minimal I/O (where the 'bytea' contents is already valid
UTF8 and the database encoding is also UTF8, and the column is not
part of any index or anything involving collation), how unsafe is the
following?

UPDATE pg_attribute SET atttypid='text'::regtype::oid WHERE
attrelid=('schema_name.table_name')::regclass AND attname='col_name'
AND atttypid='bytea'::regtype::oid;

Additionally, if the 'bytea' happenned to also explicitly contain a
trailing NUL prior to the "conversion" (i.e. after the hack, the last
byte in the 'text' value would be NUL), would there be any obvious
problems with the above hack?

Thanks,
V.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andreas Joseph Krogh 2011-05-10 20:37:07 Re: Table name as parameter
Previous Message Mark 2011-05-10 19:20:05 Re: track functions call