Class::DBI::SQL::Transformer::Quotify - Quote column and table names in Class::DBI-generated SQL


Version 0.02


  package Foo;
  use base qw/Class::DBI/;
  __PACKAGE__->connection('DBI:Mock:', '', '');
  __PACKAGE__->table('table name');
  __PACKAGE__->columns( Essential => 'my id', 'my name' );
  package main;
  my $row = Foo->retrieve( 3 );


This is an attempt to solve the problem of spaces and/or reserved words in table and/or column names. Normally, Class::DBI does not quote these, so it results in sql such as the following (which clearly will error out):

  SELECT my id, my name
  FROM table name
  WHERE my id = ?

This is implemented by subclassing Class::DBI::SQL::Transformer and notifying Class::DBI via its sql_transformer_class() attribute. Note that some of the methods are completely replaced.


I first came upon Class::DBI::Plugin::Backtickify, which worked great, except the naming of the schema was so bad I hit an edge case that needed fixing first, which got me looking under the hood:

Since that version of Class::DBI::Plugin::Backtickify, Class::DBI (as of v3.0.8) had refactored the Class::DBI::SQL::Transformer class and introduced the Class::DBIsql_transformer_class() method. Which is why this module has the namespace it does instead of Class::DBI::Plugin:: and why I didn't just submit a patch for Backtickify.

Drawing heavily from Backtickify, i generalized it to this module by using DBI::quote_identifier() instead of a hardcoded backtick.

This potentially is (at least a partial) solution (or workaround) for Class::DBI RT ticket 7715 Class::DBI does not correctly quote column names (Pg, maybe others):

In the course of investigation, also reported this Class::DBI issue, which this module also resolves:


David Westbrook (CPAN: davidrw), <dwestbrook at>


Please report any bugs or feature requests to bug-class-dbi-sql-transformer-quotify at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc Class::DBI::SQL::Transformer::Quotify

You can also look for information at:


Class::DBI, Class::DBI::SQL::Transformer, DBI, Class::DBI::Plugin::Backtickify


David Baird for the groundwork of Class::DBI::Plugin::Backtickify


Copyright 2008 David Westbrook, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.