[SearchBuilder-devel] [BUG] Pg and char data type

Ruslan Zakirov ruslan.zakirov at gmail.com
Wed Sep 21 23:14:41 EDT 2005


On 9/22/05, Robert Spier <rspier at pobox.com> wrote:
> > Pg adds trailing spaces for CHAR columns when other DBD drivers don't do this.
>
> If this is a DBD bug, it should be reported to the DBD-Pg maintainers.
I thought it's normal for Pg to extend CHAR(N) column values with
trailing spaces to its length - N, but look on the test results below.

For example MySQL deletes trailing spaces on VARCHARs. Here is example:
mysql> create table tests ( myvarchar varchar(4), mychar char(4) );
mysql> insert into tests values( 'wo', 'wo' );
mysql> insert into tests values( 'wi  ', 'wi  ' );
mysql> select *, length(myvarchar), length(mychar) from tests;
+-----------+--------+-------------------+----------------+
| myvarchar | mychar | length(myvarchar) | length(mychar) |
+-----------+--------+-------------------+----------------+
| wo        | wo     |                 2 |              2 |
| wi        | wi     |                 2 |              2 |
+-----------+--------+-------------------+----------------+
2 rows in set (0.00 sec)

Hm, output from psql console for the same test looks strange:
 myvarchar | mychar | length | length
-----------+--------+--------+--------
 wo        | wo     |      2 |      2
 wi        | wi     |      4 |      2
I can't say where is bug in DBD-Pg or Pg or may be in both, I'm not
very familiar with Pg.


Anyway we should define one variant that we want for all DB back-ends,
and follow it.

For this situation I suggest to trim trailing spaces on values that
was taken from [VAR]CHAR columns.

> _______________________________________________
> SearchBuilder-devel mailing list
> SearchBuilder-devel at bestpractical.com
> http://lists.bestpractical.com/cgi-bin/mailman/listinfo/searchbuilder-devel
>


--
Best regards, Ruslan.


More information about the SearchBuilder-devel mailing list