pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Stephan Szabo <sszabo@megazone23.bigpanda.com>
Cc: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
Cc: Hackers <pgsql-hackers@postgresql.org>
Subject: Re: [SQL] how to change the type
Date: Fri, 07 Dec 2001 10:36:13 -0500
Message-ID: <29705.1007739373@sss.pgh.pa.us> (raw)
In-Reply-To: <20011206183802.E30420-100000@megazone23.bigpanda.com>
References: <20011206183802.E30420-100000@megazone23.bigpanda.com>

Stephan Szabo <sszabo@megazone23.bigpanda.com> writes:
> IIRC, the values are stored as length + data.  I think char() might
> do wierd things (I don't know if the trailing spaces are stored), but
> varchar() and text should be expandable because anything that could have
> fit before should still fit and look the same.

Yup, exactly.

> Going down is
> problematic, because if you have a varchar(5) field where one value is say
> 'abcd' and you make it varchar(3) what happens?

What would actually happen right now is nothing: the value would still
be 'abcd' and would still read out that way.  The 3-char limit would
only get enforced during inserts and updates of the column.

char(N) does store the trailing spaces, so altering N would give
unwanted results: again, existing values would read out with the old
width until updated.  You could fix this by issuing

	UPDATE tab SET col = col

after tweaking the pg_attribute.atttypmod value.  (AFAICS, any "clean"
implementation would have to do just that internally, with the same
unpleasant space and speed implications as we've discussed for DROP
COLUMN.)

			regards, tom lane



view thread (5+ messages)  latest in thread

Message-ID: <29705.1007739373@sss.pgh.pa.us>
Permalink:  ../29705.1007739373@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/29705.1007739373@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, sszabo@megazone23.bigpanda.com, chriskl@familyhealth.com.au, pgsql-hackers@postgresql.org
  Subject: Re: [SQL] how to change the type
  In-Reply-To: <29705.1007739373@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox