diff --git a/lib/SQL/Translator/Producer/PostgreSQL.pm b/lib/SQL/Translator/Producer/PostgreSQL.pm index 455f745df..3b3e85ad9 100644 --- a/lib/SQL/Translator/Producer/PostgreSQL.pm +++ b/lib/SQL/Translator/Producer/PostgreSQL.pm @@ -99,7 +99,7 @@ my %truncated; =head1 PostgreSQL Create Table Syntax - CREATE [ [ LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name ( + CREATE [ [ LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE table_name ( { column_name data_type [ DEFAULT default_expr ] [ column_constraint [, ... ] ] | table_constraint } [, ... ] ) @@ -321,8 +321,11 @@ sub create_table $create_statement .= "DROP TABLE $table_name_qt CASCADE;\n"; } } - my $temporary = $table->extra->{temporary} ? "TEMPORARY " : ""; - $create_statement .= "CREATE ${temporary}TABLE $table_name_qt (\n" . + my $parameter = + $table->extra->{temporary} ? "TEMPORARY " + : $table->extra->{unlogged} ? "UNLOGGED " + : ""; + $create_statement .= "CREATE ${parameter}TABLE $table_name_qt (\n" . join( ",\n", map { " $_" } @field_defs, @constraint_defs ). "\n)" ; diff --git a/t/47postgres-producer.t b/t/47postgres-producer.t index 9c50db736..9c0e44d81 100644 --- a/t/47postgres-producer.t +++ b/t/47postgres-producer.t @@ -708,4 +708,31 @@ CREATE VIEW view_foo ( id, name ) AS is($drop_view_9_1_produced, $drop_view_9_1_expected, "My DROP VIEW statement for 9.1 is correct"); +{ + my $table = SQL::Translator::Schema::Table->new( name => 'foo.bar', extra => { unlogged => 1 }, ); + my $field = SQL::Translator::Schema::Field->new( name => 'baz', + table => $table, + data_type => 'VARCHAR', + size => 10, + default_value => 'quux', + is_auto_increment => 0, + is_nullable => 0, + is_foreign_key => 0, + is_unique => 0 ); + $table->add_field($field); + my ($create, $fks) = SQL::Translator::Producer::PostgreSQL::create_table($table, { quote_table_names => q{"} }); + + my $expected = <