Re: extra spaces

From: Alvaro Herrera <alvherre(at)protecne(dot)cl>
To: <pgsql-general(at)postgresql(dot)org>
Cc: <php-db(at)lists(dot)php(dot)net>
Subject: Re: extra spaces
Date: 2000-12-19 13:56:58
Message-ID: Pine.LNX.4.30.0012191044300.22413-100000@aguila.protecne.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 15 Dec 2000, Roland Roberts wrote:

> >>>>> "Soma" == Soma Interesting <dfunct(at)telus(dot)net> writes:
>
> 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.
>
> I guess I missed the orginal post about the problem, but...
>
> Are your columns char() or varchar()? The former is padded in
> PostgreSQL but not MySQL. The latter is what you really want.

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.

--
Alvaro Herrera (<alvherre[(at)]protecne(dot)cl>)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Lambert Sonna Momo 2000-12-19 14:33:25 migrate mysql to postgres
Previous Message Nick Fankhauser 2000-12-19 13:29:54 RE: grant a db