Skip to content

Commit

Permalink
Usage clarification
Browse files Browse the repository at this point in the history
  • Loading branch information
SPodjasek committed Jun 24, 2015
1 parent 2744130 commit c5b8904
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions t/47postgres-producer.t
Original file line number Diff line number Diff line change
Expand Up @@ -629,11 +629,11 @@ is($view2_sql1, $view2_sql_replace, 'correct "CREATE OR REPLACE VIEW" SQL 2');
}

{
my $index = $table->add_index(name => 'myindex', options => [{using => 'hash'}, {where => 'predicate'}], fields => ['bar', 'lower(foo)']);
my $index = $table->add_index(name => 'myindex', options => [{using => 'hash'}, {where => "upper(foo) = 'bar' AND bar = 'foo'"}], fields => ['bar', 'lower(foo)']);

This comment has been minimized.

Copy link
@SPodjasek

SPodjasek Jun 24, 2015

Author Contributor

According to docs WHERE can be normal condition, so to be totally proper it should be written as:

my $index = $table->add_index(name => 'myindex', options => [{using => 'hash'}, {where => {'upper(foo)' => 'bar', bar => 'foo'}}], fields => ['bar', 'lower(foo)']);

But this would require code similar to SQL::Abstract->where.

my ($def) = SQL::Translator::Producer::PostgreSQL::create_index($index);
is($def, "CREATE INDEX myindex on foobar USING hash (bar, lower(foo)) WHERE predicate", 'index using & where created');
is($def, "CREATE INDEX myindex on foobar USING hash (bar, lower(foo)) WHERE upper(foo) = 'bar' AND bar = 'foo'", 'index using & where created');
($def) = SQL::Translator::Producer::PostgreSQL::create_index($index, $quote);
is($def, 'CREATE INDEX "myindex" on "foobar" USING hash ("bar", lower(foo)) WHERE predicate', 'index using & where created w/ quotes');
is($def, 'CREATE INDEX "myindex" on "foobar" USING hash ("bar", lower(foo)) WHERE upper(foo) = \'bar\' AND bar = \'foo\'', 'index using & where created w/ quotes');
}
}

Expand Down

0 comments on commit c5b8904

Please sign in to comment.