This was an unexpected difference between these two types and I wonder
if it was meant to be this way.  Previously, a char8 field with the
string 'abc' would return 'abc' as expected.  Now, with char(8), I get
back 'abc     ' instead.  You can see this with my PygreSQL module
or the C interface (which my module uses, of course.)  This causes a
lot of my programs to break.

I have made a quick change to my Python module to handle this.  Should
I clean it up or can I expect the behaviour to go back the way it was?

-- 
D'Arcy J.M. Cain <darcy@{druid|vex}.net>   |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 424 2871     (DoD#0082)    (eNTP)   |  what's for dinner.

Thu, 14 May 1998 10:40:39 -0400 (EDT)
darcy@druid.net (D'Arcy J.M. Cain)
char(8) vs char8


D'Arcy J.M. Cain wrote:

> This was an unexpected difference between these two types and I wonder
> if it was meant to be this way.  Previously, a char8 field with the
> string 'abc' would return 'abc' as expected.  Now, with char(8), I get
> back 'abc     ' instead.  You can see this with my PygreSQL module
> or the C interface (which my module uses, of course.)  This causes a
> lot of my programs to break.
>

char(x) is the datatype 'bpchar' (blank padded char).  Thus it is padded
with spaces to the field width.

Couldn't you use something like "select rtrim(column) from table".  This
will trim the spaces off.

Byron


Thu, 14 May 1998 10:55:08 -0400
Byron Nikolaidis <byronn@insightdist.com>
Re: [HACKERS] char(8) vs char8
> This was an unexpected difference between these two types and I wonder
> if it was meant to be this way.  Previously, a char8 field with the
> string 'abc' would return 'abc' as expected.  Now, with char(8), I get
> back 'abc     ' instead.  You can see this with my PygreSQL module
> or the C interface (which my module uses, of course.)  This causes a
> lot of my programs to break.
> 
> I have made a quick change to my Python module to handle this.  Should
> I clean it up or can I expect the behaviour to go back the way it was?

The behavior you want is varchar() rather than char().

                    - Tom

Thu, 14 May 1998 15:27:18 +0000
"Thomas G. Lockhart" <lockhart@alumni.caltech.edu>
Re: [HACKERS] char(8) vs char8
Thus spake Byron Nikolaidis
> > string 'abc' would return 'abc' as expected.  Now, with char(8), I get
> > back 'abc     ' instead.  You can see this with my PygreSQL module
> 
> Couldn't you use something like "select rtrim(column) from table".  This
> will trim the spaces off.

It wouldn't be as convenient as this example.

import pg
for d in pg.connect('database').query('select * from table').dictresult():
    print "Num: %(field1)3d, '%(field2)s'" % d

-- 
D'Arcy J.M. Cain <darcy@{druid|vex}.net>   |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 424 2871     (DoD#0082)    (eNTP)   |  what's for dinner.

Thu, 14 May 1998 13:10:44 -0400 (EDT)
darcy@druid.net (D'Arcy J.M. Cain)
Re: [HACKERS] char(8) vs char8
Thus spake Thomas G. Lockhart
> > string 'abc' would return 'abc' as expected.  Now, with char(8), I get
> > back 'abc     ' instead.  You can see this with my PygreSQL module
> The behavior you want is varchar() rather than char().

Right.  Dump and reload time I guess.  >:-/

-- 
D'Arcy J.M. Cain <darcy@{druid|vex}.net>   |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 424 2871     (DoD#0082)    (eNTP)   |  what's for dinner.

Thu, 14 May 1998 13:12:21 -0400 (EDT)
darcy@druid.net (D'Arcy J.M. Cain)
Re: [HACKERS] char(8) vs char8