Mojo::Pg and bytea don't seem to work

27 views
Skip to first unread message

Alejandro Imass

unread,
Jun 16, 2017, 4:00:56 PM6/16/17
to Mojolicious
Hi,

Bytea values are coming back as empty strings. Am I missing something or is this a limitation and if so, is there a workaround?

TIA,
Alejandro Imass

Alejandro Imass

unread,
Jun 16, 2017, 4:24:09 PM6/16/17
to mojol...@googlegroups.com
Seems like a DBI issue and requires some explicit spec on the Pg
datatype and bind the params manually...
Anyone have an example by any chance (for selects and/or insert/update) ??

TIA,
Alejandro Imass

Dan Book

unread,
Jun 16, 2017, 4:33:41 PM6/16/17
to mojol...@googlegroups.com
The recently added bind type support should help, see the last example here: https://metacpan.org/pod/Mojo::Pg::Database#query


TIA,
Alejandro Imass

--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscribe@googlegroups.com.
To post to this group, send email to mojol...@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Alejandro Imass

unread,
Jun 17, 2017, 8:57:56 AM6/17/17
to mojol...@googlegroups.com
On Fri, Jun 16, 2017 at 4:33 PM, Dan Book <gri...@gmail.com> wrote:
> The recently added bind type support should help, see the last example here:
> https://metacpan.org/pod/Mojo::Pg::Database#query
>

Thanks Dan!

You are right. That seems to work for insert, supported by query()

But for retrieval queries (using query() or select()) I think the
limitation is in $results->hash only expands json or jsonb in the
_expand subroutine in Mojo::Pg::Results

Looking at the code in _expand (some of it is a bit mind bending)
maybe there is a way to do it by querying a single field in the select
statement (single field select with type=PG_BYTEA) but I tried several
ways and none worked.

I believe adding a new case to the json/jsonb case in _results for the
bytea type and support "raw" bytes could solve the issue but I am time
constrained and it's cheaper for me to change the database model for
now than trying to hack away at this.

It would be nice though if this is supported in the future or if
someone volunteers to submit a patch in this regard.

Best,
Alejandro Imass

sri

unread,
Jun 17, 2017, 9:15:36 AM6/17/17
to Mojolicious
It would be nice though if this is supported in the future or if
someone volunteers to submit a patch in this regard.

Patches welcome, allowing custom expanders (besides JSON) for Mojo::Pg is a planned
feature. It gets requested a lot but nobody ever volunteers for implementing it.

--
sebastian

Alejandro Imass

unread,
Jun 17, 2017, 9:59:50 AM6/17/17
to mojol...@googlegroups.com
Thanks Sebastian!

If I finish this on time I will try to get it working and fully
understand the idx, name logic ;-)

I could figure out that $idx is for array and $name is for hash but
wasn't sure about many things such as in which cases @$self{qw(idx
name)} would be pre-set when entering _expand (i.e. when would this
happen: my ($idx, $name) = @$self{qw(idx name)} when entering
_expand??);

I guess fully custom expanders seems like a bit of work but supporting
a few non-standard automatic cases like bytea and maybe couple of
others does not seem that much work (just MHO since it's the first
time doing anything serious with Mojo::Pg)

Best,
Alejandro Imass
Reply all
Reply to author
Forward
0 new messages