Set name_sep for default SQL::Abstract to help disambiguate columns #39

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

@Epiphero

When using SQL::Abstract with multiple tables, it is sometimes necessary to disambiguate columns:

$pg->db->select(['foo', 'bar'], ['foo.id'], {'foo.id', => {-ident => 'bar.id'}});

If SQL::Abstract does not have a name_sep specified, it will attempt to quote the entire table-field name as "foo.id" and "bar.id" rather than "foo"."id" and "bar"."id", producing an error such as:

DBD::Pg::st execute failed: ERROR:  column "foo.id" does not exist
LINE 1: SELECT "foo.id" FROM "foo", "bar" WHERE ( "foo.id" = "bar.id...
               ^ at lib/Test.pm line 50.

The workaround is to create the Mojo::Pg instance with:

    $pg = Mojo::Pg
      ->new($db_uri)
      ->abstract(SQL::Abstract->new(quote_char => '"', name_sep => '.'))
      ;

However, since the name_sep and quote_char values are intrinsic to Postgres, it makes sense for these to be the setting on the default SQL::Abstract object.

@kraih kraih closed this in 0bfd3e7 Feb 18, 2017
@kraih
Owner
kraih commented Feb 18, 2017

Thank you, applied with tests and documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment