Re: extra spaces

From: "Mark Cowlishaw" <markc(at)ot(dot)com(dot)au>
To: "Alvaro Herrera" <alvherre(at)protecne(dot)cl>, <pgsql-general(at)postgresql(dot)org>
Cc: <php-db(at)lists(dot)php(dot)net>
Subject: Re: extra spaces
Date: 2000-12-19 23:35:01
Message-ID: 015301c06a14$4e939980$5250460a@meta2k
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


> > Soma> All values called from the database are still padded with
> > Soma> extra spaces from the column size in the database. Is this
> > Soma> normal - I don't remember this happening when I was using
> > Soma> MySQL. I thought usually the database stripped the extra
> > Soma> spaces when it retrieved the values.

>
> According to "Postgres: Introduction and Concepts", varchar is slower
> than char. So if you (like me) want to use char and get rid of the
> padding spaces, you may use a regex replacement, as in
>
> while (@row=$result->fetchrow)
> {
> $row[0] =~ s/[\s]+$//;
> }
>
> in perl, or
>
> $array["name"]=preg_replace("'[\s]+$'", "", $array["name"], -1);
>
> in PHP.
>

I'm new to the list so I'm not sure if this has already been said, but Perl
DBI has an option to trim trailing spaces in the connect statement. eg:

my $dbh = DBI->connect("dbi:Pg:dbname=mydb",
'myuser','mypass',
{RaiseError => 1, AutoCommit => 0, ChopBlanks => 1})
or die $DBI::errstr;

Cheers

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Oliver Elphick 2000-12-19 23:46:59 Re: Character encoding problem using Tcl
Previous Message Peter Eisentraut 2000-12-19 23:12:11 Re: Generating HISTORY file