@@ -1514,7 +1514,7 @@ sub parse_dump
15141514
15151515 }
15161516 elsif ($line =~
1517- / ^\s *(?:CONSTRAINT \[ (.*)\] )?PRIMARY KEY (?:NON)?CLUSTERED/ )
1517+ / ^\s *(?:CONSTRAINT \[ (.*)\] )?PRIMARY KEY (?:NON)?CLUSTERED(?: HASH)? / )
15181518 {
15191519 my $constraint
15201520 ; # We put everything inside this hashref, we'll push it into the constraint list later
@@ -1823,7 +1823,7 @@ sub parse_dump
18231823 }
18241824
18251825 elsif ($line =~
1826- / ^CREATE\s *(UNIQUE )?\s *(NONCLUSTERED|CLUSTERED)?\s *INDEX \[ (.*?)\] ON \[ (.*?)\]\.\[ (.*?)\] (\(\[ .*?\]\) )?/
1826+ / ^\s * CREATE\s *(UNIQUE )?\s *(NONCLUSTERED|CLUSTERED)?\s *INDEX \[ (.*?)\] ON \[ (.*?)\]\.\[ (.*?)\] (\(\[ .*?\]\) )?/
18271827 )
18281828 {
18291829 # Index creation. Index are namespaced per table in SQL Server, not in PostgreSQL
@@ -2249,6 +2249,14 @@ sub parse_dump
22492249 }
22502250 }
22512251
2252+ # Save variable for future use
2253+ elsif ($line =~ / ^:setvar\s +(\S +)\s +"(.*)"/ )
2254+ {
2255+ my $varname = $1 ;
2256+ my $varvalue = $2 ;
2257+ $objects -> {VARIABLES }-> {$varname } = $varvalue ;
2258+ next ;
2259+ }
22522260
22532261 # Ignore USE, GO, and things that have no meaning for postgresql
22542262 elsif ($line =~
@@ -2444,6 +2452,12 @@ sub generate_schema
24442452 }
24452453 }
24462454
2455+ # Set psql variables in UNSURE
2456+ foreach my $varname (sort keys %{$objects -> {VARIABLES }})
2457+ {
2458+ print UNSURE " \\ set $varname '$objects ->{VARIABLES}->{$varname }'\n " ;
2459+ }
2460+
24472461 # For the rest, we iterate over schemas, except for array types (no point in complicating this)
24482462 # The tables, columns, etc... will be created in the before script, so there is no dependancy
24492463 # problem with constraints, that will be in the after script, except foreign keys which depend on unique indexes
@@ -2777,9 +2791,15 @@ sub generate_schema
27772791 {
27782792 my $colref = $refschema -> {TABLES }-> {$table }-> {COLS }-> {$col };
27792793 next unless (defined $colref -> {DEFAULT });
2794+ my $default_value = $colref -> {DEFAULT }-> {VALUE };
2795+ if ($default_value =~ / \(\$\( (\S +)\)\) / )
2796+ {
2797+ $default_value = " :$1 " ;
2798+ }
27802799 my $definition =
2781- " ALTER TABLE " . format_identifier($schema ) . ' .' . format_identifier($table ) . " ALTER COLUMN " . format_identifier($col ) . " SET DEFAULT "
2782- . $colref -> {DEFAULT }-> {VALUE } . " ;\n " ;
2800+ " ALTER TABLE " . format_identifier($schema ) . ' .' . format_identifier($table )
2801+ . " ALTER COLUMN " . format_identifier($col )
2802+ . " SET DEFAULT " . $default_value . " ;\n " ;
27832803 if ($colref -> {DEFAULT }-> {UNSURE })
27842804 {
27852805 print UNSURE $definition ;
0 commit comments