Search code examples
perldbi

DBI: quote_identifier and columns


In the DBI/quote_identifier documentation there are two syntaxes:

$sql = $dbh->quote_identifier( $name );
$sql = $dbh->quote_identifier( $catalog, $schema, $table, \%attr );

And the examples are about table names.

Is there something to object if one uses quote_identifier like this to quote columns:

$sql = $dbh->quote_identifier( undef, $table, $column );

Solution

  • Yes, that is fine. quote_identifier cannot and does not try to distinguish between table names and column names, and every database that I know has the same syntax for them. The only problem comes when you want column names like schema.table.column, which you will have to construct yourself from multiple calls to quote_identifier.