Re: [dabo-users] PostgreSQL char fields are rpadded

Author: Adrian Klaver

Posted: 2011-11-18 at 12:10:01

On Friday, November 18, 2011 9:00:36 am Richard Kaye wrote:

> Sounds like DBF style behavior to me. :)

>

No its SQL standard behavior:

http://www.postgresql.org/docs/9.0/interactive/datatype-character.html

"SQL defines two primary character types: character varying(n) and character(n),

where n is a positive integer. Both of these types can store strings up to n

characters (not bytes) in length. An attempt to store a longer string into a

column of these types will result in an error, unless the excess characters are

all spaces, in which case the string will be truncated to the maximum length.

(This somewhat bizarre exception is required by the SQL standard.) If the string

to be stored is shorter than the declared length, values of type character will

be space-padded; values of type character varying will simply store the shorter

string.

If one explicitly casts a value to character varying(n) or character(n), then an

over-length value will be truncated to n characters without raising an error.

(This too is required by the SQL standard.) " ...

..."Values of type character are physically padded with spaces to the specified

width n, and are stored and displayed that way. However, the padding spaces are

treated as semantically insignificant. Trailing spaces are disregarded when

comparing two values of type character, and they will be removed when converting

a character value to one of the other string types. Note that trailing spaces

are semantically significant in character varying and text values. "

--

Adrian Klaver

adrian.klaver@gmail.com

_______________________________________________

Post Messages to: Dabo-users@leafe.com

Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users

Searchable Archives: http://leafe.com/archives/search/dabo-users

This message: http://leafe.com/archives/byMID/201111180910.02007.adrian.klaver@gmail.com

©2011 Adrian Klaver