I have a subroutine I use to insert a records into a postgres database using DBI and DBD::Pg as a driver. I've used it for years with no problems. $dbh is an established connection, and $data is a reference to a hash with the column names and values to be inserted:
sub insertsql { my ($dbh,$table,$data) = @_; my @qm; my @keys; my @values; my $i = -1; foreach my $k (keys %$data) { if (defined($data->{$k})) { $i++; $keys[$i] = $k; $values[$i] = $data->{$k}; $qm[$i] = '?'; } } my $keylist = join(",",@keys); my $qlist = join(",",@qm); my $sqlstatement = "insert into $table ($keylist) values ($qlist) +returning id"; my $sth = $dbh->prepare($sqlstatement); $sth->execute(@values) || die $sth->errstr; $sth->finish(); return; }
I am using this to insert some crowdtangle data. After the 17th line, $sqlstatement looks like this:

insert into crowdtangle (postUrl,crowdtangle_id,statistics,account,dew +indowfy_content,expandedLinks,score,description,message,posted,media, +subscriberCount,updated,platform,type) values (?,?,?,?,?,?,?,?,?,?,?, +?,?,?,?) returning id

When I execute the query I get this:

DBD::Pg::st execute failed: ERROR: column "posturl" of relation "crow +dtangle" does not exist LINE 1: insert into crowdtangle (postUrl,crowdtangle_id,statistics,a.. +. ^ at c:/perlmodules/SqlSupport.pm lin +e 70.
It is right, column posturl does not exist. The column name is postUrl with a capital U, like I had it in the query. What could be going on here?

In reply to DBI/DBD::Pg changing my sql query somehow? by cormanaz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.