From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | pgsql-hackers(at)postgreSQL(dot)org |
Subject: | charin(), text_char() should return something else for empty input |
Date: | 2001-05-28 16:55:00 |
Message-ID: | 13338.991068900@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
I have been chasing Domingo Alvarez Duarte's report of funny behavior
when assigning an empty string to a "char" variable in plpgsql. What
it comes down to is that text-to-char conversion does not behave very
well for zero-length input. charin() returns a null character, leading
to the following bizarreness:
regression=# select 'z' || (''::"char") || 'q';
?column?
----------
z
(1 row)
regression=# select length('z' || (''::"char") || 'q');
length
--------
3
(1 row)
The concatenation result is 'z\0q', which doesn't print nicely :-(.
text_char() produces a completely random result, eg:
regression=# select ''::text::"char";
?column?
----------
~
(1 row)
and could even coredump in the worst case, since it tries to fetch the
first character of the text input no matter whether there is one or not.
I propose that both of these operations should return a space character
for an empty input string. This is by analogy to space-padding as you'd
get with char(1). Any objections?
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Oleg Bartunov | 2001-05-28 17:01:59 | R-Tree implementation using GiST (compatible with multi-key GiST) |
Previous Message | Jim Mercer | 2001-05-28 16:12:53 | Re: Re: OpenOffice compile |