char() datatype looses strings of all spaces - Mailing list pgsql-hackers

From Joe Conway
Subject char() datatype looses strings of all spaces
Date
Msg-id 3F3F0D8B.4060802@joeconway.com
Whole thread Raw
Responses Re: char() datatype looses strings of all spaces
Re: char() datatype looses strings of all spaces
List pgsql-hackers
I stumbled across this behavior today and it seems strange if not a bug:

-- this seems wrong
vsconf=# create table foo (f1 char(1));
CREATE TABLE
vsconf=# insert into foo values(' ');
INSERT 9002011 1
vsconf=# select ascii(f1) from foo; ascii
-------     0
(1 row)

-- this is what I'd expect
vsconf=# create table foo2 (f1 varchar(1));
CREATE TABLE
vsconf=# insert into foo2 values(' ');
INSERT 9002015 1
vsconf=# select ascii(f1) from foo2; ascii
-------    32
(1 row)

-- this seems wrong
vsconf=# create table foo4 (f1 char(5));
CREATE TABLE
vsconf=# insert into foo4 values('     ');
INSERT 9002022 1
vsconf=# select ascii(f1) from foo4; ascii
-------     0
(1 row)

I looked for a few minutes at bpcharin(), but could not see exactly why 
this is happening. Am I missing something wrt the char() data type, or 
is this a bug?

Joe



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: "truncate all"?
Next
From: Bruce Momjian
Date:
Subject: Re: Parsing speed (was Re: pgstats_initstats() cost)