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

Reply via email to