From 5d048eb95cdcca4e184e33369b16df5da4651ac7 Mon Sep 17 00:00:00 2001 From: Eugen Konkov Date: Fri, 20 Oct 2017 17:20:05 +0300 Subject: [PATCH] Improve create_index --- lib/SQL/Translator/Producer/PostgreSQL.pm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/SQL/Translator/Producer/PostgreSQL.pm b/lib/SQL/Translator/Producer/PostgreSQL.pm index 455f745df..4ad954107 100644 --- a/lib/SQL/Translator/Producer/PostgreSQL.pm +++ b/lib/SQL/Translator/Producer/PostgreSQL.pm @@ -923,7 +923,13 @@ sub alter_create_index { my ($index, $options) = @_; my $generator = _generator($options); my ($idef, $constraints) = create_index($index, $options); - return $index->type eq NORMAL ? $idef + + # Just like 90726ffd commit: don't run into output like this: + # ALTER TABLE users ADD ; + # create_index returns one of: index definition or constraint + + # So define index or constraint + return $idef ? $idef : sprintf('ALTER TABLE %s ADD %s', $generator->quote($index->table->name), join(q{}, @$constraints)