Re: ALTER TEXT field to VARCHAR(1024)

From: Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>
To: Marius Grama <mariusneo(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: ALTER TEXT field to VARCHAR(1024)
Date: 2014-09-19 07:45:25
Message-ID: 541BDF15.5030202@archidevsys.co.nz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 19/09/14 19:32, Marius Grama wrote:
> Hello,
>
>
> i am using Postgres 9.2 and I'd like to perform the following ALTER
> statement on a database table with about 30M entries :
>
> ALTER TABLE images ALTER COLUMN mask_descriptors TYPE VARCHAR(1024);
>
> The mask_descriptors field is currently having the type TEXT.
> I want to perform the ALTER due to the fact that it seems that copying
> the contents of the table to a BI SQL Server is done in row by row
> (instead of batch) when handling CLOBs.
>
> From the Postgres documentation I got the following :
>
> http://www.postgresql.org/docs/8.3/static/datatype-character.html
>
> Tip: There are no performance differences between these three
> types, apart from increased storage size when using the
> blank-padded type, and a few extra cycles to check the length when
> storing into a length-constrained column. While character has
> performance advantages in some other database systems, it has no
> such advantages in PostgreSQL. In most situations text or
> character varying should be used instead.
>
>
>
> Can anybody explain me what happens in the background when the alter
> statement is executed? I've tried it out on a small copy of the table
> (70K) and the operation completed in 0.2 seconds.
> Will the table be completely locked during the execution of the ALTER
> statement?
>
>
>
I am curious as to why you want to change text to VARCHAR(1024),
especially as I think that the middleware should be controlling how long
a string is saved in the database rather than end user client code (for
several reasons., including security concerns). However, I do not know
your use cases, nor your overall situation - so my concerns may not
apply to you.

Cheers,
Gavin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dev Kumkar 2014-09-19 07:51:16 Re: [SQL] pg_multixact issues
Previous Message Andres Freund 2014-09-19 07:33:57 Re: [GENERAL] pg_multixact issues