Sounds like DBD::Pg should know better than to do that!
But then, DBD::mysql has the same problem.  So maybe it is at the DBI level?

On Fri, Feb 25, 2011 at 5:50 PM, Bill Moseley <mose...@hank.org> wrote:

> Columns coming from DBD::Pg seems to all be Perl strings and then when I
> encode to json then end up quoted:
>
> music=# \d cd;
>                          Table "public.cd"
>  Column  |  Type   |                    Modifiers
> ---------+---------+-------------------------------------------------
>  id      | integer | not null default nextval('cd_id_seq'::regclass)
>  year    | integer |
>  name    | text    |
>  artist  | integer | not null
>  deleted | boolean | not null default false
> Indexes:
>    "cd_pkey" PRIMARY KEY, btree (id)
>
>
> my $x = $dbh->selectrow_hashref( "select * from cd where id = 1" );
> $x->{foo} = 0;
>
> print Dumper $x;
> print encode_json( $x );
>
> Results in:
>
> $VAR1 = {
>          'artist' => '1',
>          'name' => 'One first CD',
>          'foo' => 0,
>          'deleted' => '0',
>          'id' => '1',
>          'year' => '2010'
>        };
> {"artist":"1","name":"One first
> CD","foo":0,"deleted":"0","id":"1","year":"2010"}
>
> Notice how the deleted boolean and integer columns are quoted, but the
> "foo"
> I injected is not quoted?
>
> In a javascript library we are using it's seeing the deleted value as true.
>  So, I'm curious if I can make DBI (or DBD::Pg) return the non-text columns
> looking like numbers to Perl.
>
> I suppose I could do something silly like:
>
> /^\d+$/ && ($_ += 0) for values %{$x};
>
>
> which then returns:
>
> {"artist":1,"name":"One first CD","foo":0,"deleted":0,"id":1,"year":2010}
>
> --
> Bill Moseley
> mose...@hank.org
>



-- 
Check out my LEGO blog at http://www.brickpile.com/
View my photos at http://flickr.com/photos/billward/
Follow me at http://twitter.com/williamward

Reply via email to