DBI::execute(): how to evade quoting identifier names



Hi all,

thanks for the quick solution to my previous __FUNCTION__ question. I have another problem:

I try to execute the following SQL query in PostGreSQL 8.1. However, it gives errors since DBI::execute() automatically quotes when it inserts its arguments into the SQL query. Is there any way to change the quoting behavior of DBI::execute():

# make SQL statement
my $qry = "ALTER TABLE mytable ALTER COLUMN ? TYPE double precision;

# prepare SQL-statement
my $qry_sth = $dbh->prepare($qry);

# execute SQL statement with user-defined column name added
$qry_sth->execute($col_name);

which results in the following query being executed:
ALTER TABLE mytable ALTER COLUMN 'column_name' TYPE double precision


The inserted variable, which is an identifier, will receive single quotes by DBI::execute(). PostGreSQL gives an error, since it only accepts unquoted identifiers. How can I change DBI::prepare() or DBI::execute default behavior, so that added values go unquoted?

I have the idea that this should be done by adding some statement handling attribute to the $qry_sth object, but the DBI documentation is not very explicit about it.

thanks for any help,
Bram






.



Relevant Pages

  • Re: SQL not working in 10g Release 2
    ... > The "SQL query" I am having is quite similar to the one I have ... > What was and is happening in Oracle 10g R1 is that, when I execute this ... Regards ... The Co-operative Oracle Users' FAQ ...
    (comp.databases.oracle.server)
  • Re: Is Linq worth it?
    ... myEvenList which in turn caused the query to immediately execute and store ... If you think of it as just a SQL query (but ... I'm a lot more excited about what I can use Linq for than I ... Things like anonymous types and type ...
    (microsoft.public.dotnet.languages.vb)
  • Re: SQL Updates
    ... into separate commands and execute them. ... I have sql updates that I need to apply to the new version of my ... I can run this file on sql query analyzer to apply all the updates at ... either my file can have 'go's or semicolon. ...
    (microsoft.public.dotnet.languages.csharp)
  • SQL problem with SWI-Prolog
    ... execute an SQL query with a WHERE clause. ... I managed to execute simple SQL ... queries but my precidates always fail when i specify a WHERE clause. ... odbc_prepare(ccc, 'SELECT name, postcode FROM credit_history where ID ...
    (comp.lang.prolog)
  • Re: Problem with counting the number of lines
    ... >I have to execute an sql query and count the number of objects returned ... >by the SQL statement. ... >The above command returns objectCnt as null on some KSH shell versions ...
    (comp.unix.shell)