Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: DBD::Pg - $sth->execute($csv_var) ERROR

by Fletch (Bishop)
on Mar 11, 2020 at 18:35 UTC ( [id://11114138]=note: print w/replies, xml ) Need Help??


in reply to Re: DBD::Pg - $sth->execute($csv_var) ERROR
in thread DBD::Pg - $sth->execute($csv_var) ERROR

Just to (maybe, hopefully) clarify: if $columns contains an array ref with your 22 column names and $values the 22 corresponding values you need to call $sth->execute( @{$columns}, @{$values} ) because it expects to get a flat list of parameters (not references to arrays with them). You're giving it the first below; it wants the second:

$sth->execute( [ "col1", "col2", ... ], [ "val1", "val2", ... ] ); ## + not working $sth->execute( "col1", "col2", ..., "col22", "val1", "val2", ... ); ## + what it expects

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^3: DBD::Pg - $sth->execute($csv_var) ERROR
by perlygapes (Sexton) on Mar 13, 2020 at 00:54 UTC

    Oh the cake....yes, I know it's a lie, but it is just so tasty! :`(
    Yes, $columns and $values are strings containing comma separated column names and column values I wish to insert into Pg.

    I tried these, none of them work:

    $sth->execute(@{$columns},@{$values}); $sth->execute(@columns,@values); $sth->execute(\@columns,\@values);

    I thought $sth->execute($columns,$values); would be closer to passing the flat comma separated string Pg needs.

    What is just not clear in the DBD::Pg cpan documentation is how many arguments $sth->execute(); expects or can take, and I can't see a really clear/obvious example of where a variable is used. Most instances just show a hard-coded value...not very helpful.

      You are on the right track with Re^2: DBD::Pg - $sth->execute($csv_var) ERROR, but to understand why this doesn't work
      I thought $sth->execute($columns,$values); would be closer to passing the flat comma separated string Pg needs.
      you need to be aware of the difference between
      • a string containing comma separated list of values (in Perl: a scalar)
      • a list of values (in Perl: a list or an array)
      So, even DBI could use "placeholded" column names, you'd have to execute ( split(/,\s*/,$columns), split(/,\s*/, $values))

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11114138]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-20 07:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found