From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "Andrus" <kobruleht2(at)hot(dot)ee> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: select statement fails |
Date: | 2008-04-10 15:57:25 |
Message-ID: | 2560.1207843045@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
"Andrus" <kobruleht2(at)hot(dot)ee> writes:
> 1. SQL assumes that CHARACTER(n) column is always padded with spaces in
> right.
> So casting to text should preserve spaces.
No, it should not. In CHAR(n), trailing spaces are semantically
insignificant; 'foo' and 'foo ' are considered equal. In TEXT
they are just as significant as any other character, and those strings
are definitely not equal. So 'foo ' as CHAR(4) and 'foo ' as TEXT
do not actually mean the same thing at all, and similarly ' ' means
two different things as CHAR(1) and as TEXT, even though they look
the same.
The SQL spec's definition of CHAR(n) behavior is really pretty broken
in my opinion; you're almost always better off using varchar. In this
particular case, where you think that a space has semantic significance,
CHAR(n) is simply wrong.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | William Temperley | 2008-04-10 16:20:21 | Re: percentile rank query |
Previous Message | Erik Jones | 2008-04-10 15:46:31 | Re: select statement fails |