Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by jo37 (Deacon)
on Mar 11, 2020 at 15:25 UTC ( [id://11114132]=note: print w/replies, xml ) Need Help??


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

Just dereference your array refs.

-jo

  • Comment on Re: DBD::Pg - $sth->execute($csv_var) ERROR

Replies are listed 'Best First'.
Re^2: DBD::Pg - $sth->execute($csv_var) ERROR
by Fletch (Bishop) on Mar 11, 2020 at 18:35 UTC

    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.

      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://11114132]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-04-25 14:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found