Re: extra spaces - Mailing list pgsql-general

From Mark Cowlishaw
Subject Re: extra spaces
Date
Msg-id 015301c06a14$4e939980$5250460a@meta2k
Whole thread Raw
In response to Re: extra spaces  (Alvaro Herrera <alvherre@protecne.cl>)
Responses Re: Re: extra spaces
List 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


pgsql-general by date:

Previous
From: "Edmar Wiggers"
Date:
Subject: RE: Trigger with superuser privileges
Next
From: "Oliver Elphick"
Date:
Subject: Re: Character encoding problem using Tcl