mojolicious / mojo-pg

Mojolicious :heart: PostgreSQL
https://metacpan.org/release/Mojo-Pg
Artistic License 2.0
101 stars 46 forks source link

Problems handling JSON #74

Closed tarkhil closed 3 years ago

tarkhil commented 3 years ago

Steps to reproduce the behavior

#!/usr/bin/env perl
use Mojo::Base -base;
use SQL::Abstract::Pg;
use YAML;

my $abstract = SQL::Abstract::Pg->new;
say Dump $abstract->insert( 'some_table', {foo => {-json => [1, 2, 3]}}, {bar => 23} );

Actual behavior

 % ./tmp/insert
[SQL::Abstract::__ANON__] Warning: HASH ref as bind value in insert is not supported at ./tmp/insert line 7.
--- 'INSERT INTO some_table ( foo) VALUES ( ? )'
---
-json:
  - 1
  - 2
  - 3

Attempt to use that insert with Mojo::Pg yields "Cannot bind a reference" error

kraih commented 3 years ago

We can only use the hooks SQL::Abstract provides us. How they are handled we have no control over. You probably want to report the issue upstream.

tarkhil commented 3 years ago

So it was handled by SQL::Abstract, while being a Pg extension?... Ok...

On 17.01.2021 0:26, Sebastian Riedel wrote:

We can only use the hooks |SQL::Abstract| provides us. How they are handled we have no control over. You probably want to report the issue upstream.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mojolicious/mojo-pg/issues/74#issuecomment-761671301, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAD4K55RYKDT6PPL7JZLRPLS2IABDANCNFSM4WFRVKJA.

tarkhil commented 3 years ago

As of 1.87. SQL::Abstract does not support JSON.

And as far as I understand SQL::Abstract::Pg manual, SQL::Abstract::Pg - should, as it's a Pg extension...

kraih commented 3 years ago

That doesn't mean we can magically change SQL::Abstract internals.

karenetheridge commented 3 years ago

@tarkhil I'm not sure exactly what SQL you are expecting to be generated, but if json() is to be a function call in postgres, and its argument is a hashref, then this should do the trick:

$abstract->insert( 'some_table', {foo => \[ 'json(?)', [{}, [1,2,3] ] ]}, {bar => 23} );