From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Steve Tucknott <steve(at)retsol(dot)co(dot)uk> |
Cc: | PostGre <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: Significant trailing spaces |
Date: | 2004-08-02 14:37:51 |
Message-ID: | 10067.1091457471@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Steve Tucknott <steve(at)retsol(dot)co(dot)uk> writes:
> I still seem to get the same problem - putting a CHAR(250) variable
> (with trailing spaces) into a VARCHAR(100) gives me a VARCHAR with a
> length 100 - ie padded with spaces. Is this still correct?
This is per SQL specification. SQL92 section 9.2 "Store assignment"
defines assignment to a varchar thusly:
[ T is the target variable, V is the value being assigned ]
d) If the data type of T is variable-length character string
and the length in characters M of V is not greater than the
maximum length in characters of T, then the value of T is set
to V and the length in characters of T is set to M.
e) If the data type of T is variable-length character string and
the length in characters M of V is greater than the maximum
length in characters L of T, then,
Case:
i) If the rightmost M-L characters of V are all <space>s, then
the value of T is set to the first L characters of V and
the length in characters of T is set to L.
ii) If one or more of the rightmost M-L characters of V are
not <space>s, then an exception condition is raised: data
exception-string data, right truncation.
If you don't want the spaces, consider using the trim() or rtrim()
function.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Scott Marlowe | 2004-08-02 16:17:12 | Re: Help on triggers |
Previous Message | sql | 2004-08-02 14:09:20 | import schema |