Discussion:
[Mojolicious] Inserts and returning
Jan Eskilsson
2018-09-29 12:22:03 UTC
Permalink
Hi All

Using Mojo <https://mojolicious.org/perldoc/Mojo> :: Pg
<https://mojolicious.org/perldoc/Mojo/Pg> :: Database
<https://mojolicious.org/perldoc/Mojo/Pg/Database> latest version 4.10 I
don't get anything from the returning clause even though records are
created or exists in the stockitems table. Instead I get this error :
DBD::Pg::st fetchrow_hashref failed: no statement executing at ...
site/lib/Mojo/Pg/Results.pm line 22.

Am I doing something wrong or am I correct in assuming this construct not
supported ?

my $stockitem = $db->insert('stockitems', {
stockitem => @{$payload}[$i]->{PostID},
description => @{$payload}[$i]->{Position},
payload => $payload_json,
companies_fkey => $companies_pkey
},{on_conflict => [
['stockitem', 'companies_fkey'] => {moddatetime => $now}]},
{returning => ['stockitems_pkey']});

my $stockitems_pkey = $stockitem->hash->{stockitems_pkey};

Thank you in advance !


Best Regards
Jan
--
Titles mean nothing. The one with a servant's heart is the leader.

Please consider the environment before you print this email.

All incoming and outgoing emails and any attachments are subjected to a
virus scanner and are believed to be free of any virus, or any other defect
which might affect any computer or IT system into which they are received
and opened. Therefore, it is the responsibility of the recipient to ensure
that they are virus free and no responsibility is accepted by Jan Eskilsson
for any loss or damage arising in any way from receipt or use thereof.
--
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+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Lars Thegler
2018-09-29 12:34:29 UTC
Permalink
Without having tried it, I would assume that 'returning' and 'on_conflict'
both should be in %options?

my $results = $db->insert($table, \@values || \%fieldvals, \%options);


/Lars
Post by Jan Eskilsson
Hi All
Using Mojo <https://mojolicious.org/perldoc/Mojo> :: Pg
<https://mojolicious.org/perldoc/Mojo/Pg> :: Database
<https://mojolicious.org/perldoc/Mojo/Pg/Database> latest version 4.10 I
don't get anything from the returning clause even though records are
DBD::Pg::st fetchrow_hashref failed: no statement executing at ...
site/lib/Mojo/Pg/Results.pm line 22.
Am I doing something wrong or am I correct in assuming this construct not
supported ?
my $stockitem = $db->insert('stockitems', {
payload => $payload_json,
companies_fkey => $companies_pkey
},{on_conflict => [
['stockitem', 'companies_fkey'] => {moddatetime => $now}]},
{returning => ['stockitems_pkey']});
my $stockitems_pkey = $stockitem->hash->{stockitems_pkey};
Thank you in advance !
Best Regards
Jan
--
Titles mean nothing. The one with a servant's heart is the leader.
Please consider the environment before you print this email.
All incoming and outgoing emails and any attachments are subjected to a
virus scanner and are believed to be free of any virus, or any other defect
which might affect any computer or IT system into which they are received
and opened. Therefore, it is the responsibility of the recipient to ensure
that they are virus free and no responsibility is accepted by Jan Eskilsson
for any loss or damage arising in any way from receipt or use thereof.
--
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
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
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+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Jan Eskilsson
2018-09-29 12:43:33 UTC
Permalink
Yes of course, thank you very much for spotting that ! Now it works as
expected :-)

Best Regards
Jan
Post by Lars Thegler
Without having tried it, I would assume that 'returning' and 'on_conflict'
both should be in %options?
/Lars
Post by Jan Eskilsson
Hi All
Using Mojo <https://mojolicious.org/perldoc/Mojo> :: Pg
<https://mojolicious.org/perldoc/Mojo/Pg> :: Database
<https://mojolicious.org/perldoc/Mojo/Pg/Database> latest version 4.10
I don't get anything from the returning clause even though records are
DBD::Pg::st fetchrow_hashref failed: no statement executing at ...
site/lib/Mojo/Pg/Results.pm line 22.
Am I doing something wrong or am I correct in assuming this construct not
supported ?
my $stockitem = $db->insert('stockitems', {
payload => $payload_json,
companies_fkey => $companies_pkey
},{on_conflict => [
['stockitem', 'companies_fkey'] => {moddatetime => $now}]},
{returning => ['stockitems_pkey']});
my $stockitems_pkey = $stockitem->hash->{stockitems_pkey};
Thank you in advance !
Best Regards
Jan
--
Titles mean nothing. The one with a servant's heart is the leader.
Please consider the environment before you print this email.
All incoming and outgoing emails and any attachments are subjected to a
virus scanner and are believed to be free of any virus, or any other defect
which might affect any computer or IT system into which they are received
and opened. Therefore, it is the responsibility of the recipient to ensure
that they are virus free and no responsibility is accepted by Jan Eskilsson
for any loss or damage arising in any way from receipt or use thereof.
--
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
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
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
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
Titles mean nothing. The one with a servant's heart is the leader.

Please consider the environment before you print this email.

All incoming and outgoing emails and any attachments are subjected to a
virus scanner and are believed to be free of any virus, or any other defect
which might affect any computer or IT system into which they are received
and opened. Therefore, it is the responsibility of the recipient to ensure
that they are virus free and no responsibility is accepted by Jan Eskilsson
for any loss or damage arising in any way from receipt or use thereof.
--
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+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Loading...