title: DBD::Pg::st execute failed: ERROR: syntax error at or near "$1"
body: <p>Trying to set a value in PostgreSQL using Perl and DBI, and thus DBD::Pg.</p>
  
  <p>I'm getting an odd error.</p>
  
  <pre><code>2013-05-23 19:02:36.641139500 updating status to 0
  2013-05-23 19:02:36.641410500 DBD::Pg::st execute failed: ERROR:  syntax error at or near "$1"
  2013-05-23 19:02:36.641418500 LINE 1: UPDATE instances SET $1 = $2
  2013-05-23 19:02:36.641423500                              ^ at /usr/lib/perl5/vendor_perl/Mitel/MslRest/mbg.pm line 161.
  2013-05-23 19:02:36.642425500 [Thu May 23 19:02:36 2013] [error] DBD::Pg::st execute failed: ERROR:  syntax error at or near "$1"
  2013-05-23 19:02:36.642438500 LINE 1: UPDATE instances SET $1 = $2
  2013-05-23 19:02:36.642443500                              ^ at /usr/lib/perl5/vendor_perl/Mitel/MslRest/mbg.pm line 161.
  2013-05-23 19:02:36.642447500
  </code></pre>
  
  <p>The relevant code is</p>
  
  <pre><code>my $sql = "UPDATE instances SET ? = ?";
  my $dbh = Mitel::tug::getdbh();
  $dbh-&gt;begin_work;
  my $sth = $dbh-&gt;prepare($sql);
  unless ($sth) {
      return $self-&gt;internal_error("prepare failed: " . $dbh-&gt;errstr);
  }
  foreach my $propname (sort keys %{ $raw_data }) {
      my $propval = $raw_data-&gt;{$propname};
      print STDERR "updating $propname to $propval\n";
      if (! $sth-&gt;execute($propname, $propval)) {
          $dbh-&gt;rollback;
          $sth-&gt;finish;
          return $self-&gt;internal_error("execute: " . $dbh-&gt;errstr);
      }
  }
  $dbh-&gt;commit;
  $sth-&gt;finish;
  </code></pre>
  
  <p>So I'm trying to update "status" to 0, using the execute method to prevent sql injection, but I'm getting a syntax error for some reason.</p>
  
  <p>Anyone run into this?</p>
  
  <pre><code>root@miketug2 ~]# perl -v
  
  This is perl, v5.10.1 (*) built for i386-linux-thread-multi
  
  perl-DBD-Pg-2.15.1-4.el6_3.i686
  postgresql84-server-8.4.14-1PGDG.rhel6.i686
  
  root@miketug2 ~]# uname -a
  Linux miketug2 2.6.32-279.22.1.el6.i686 #1 SMP Wed Feb 6 00:31:03 UTC 2013 i686 i686 i386 GNU/Linux
  </code></pre>