|
118 | 118 |
|
119 | 119 | my %bki_attr; |
120 | 120 | my @attnames; |
| 121 | + my $first = 1; |
| 122 | + |
| 123 | + print BKI " (\n"; |
121 | 124 | foreach my $column (@{ $catalog->{columns} }) |
122 | 125 | { |
123 | | - my ($attname, $atttype) = %$column; |
124 | | - $bki_attr{$attname} = $atttype; |
| 126 | + my $attname = $column->{name}; |
| 127 | + my $atttype = $column->{type}; |
| 128 | + $bki_attr{$attname} = $column; |
125 | 129 | push @attnames, $attname; |
| 130 | + |
| 131 | + if (!$first) |
| 132 | + { |
| 133 | + print BKI " ,\n"; |
| 134 | + } |
| 135 | + $first = 0; |
| 136 | + |
| 137 | + print BKI " $attname = $atttype"; |
| 138 | + |
| 139 | + if (defined $column->{forcenotnull}) |
| 140 | + { |
| 141 | + print BKI " FORCE NOT NULL"; |
| 142 | + } |
| 143 | + elsif (defined $column->{forcenull}) |
| 144 | + { |
| 145 | + print BKI " FORCE NULL"; |
| 146 | + } |
126 | 147 | } |
127 | | - print BKI " (\n"; |
128 | | - print BKI join " ,\n", map(" $_ = $bki_attr{$_}", @attnames); |
129 | 148 | print BKI "\n )\n"; |
130 | 149 |
|
131 | | - # open it, unless bootstrap case (create bootstrap does this automatically) |
| 150 | + # open it, unless bootstrap case (create bootstrap does this automatically) |
132 | 151 | if ($catalog->{bootstrap} eq '') |
133 | 152 | { |
134 | 153 | print BKI "open $catname\n"; |
|
210 | 229 | # Store schemapg entries for later. |
211 | 230 | $row = |
212 | 231 | emit_schemapg_row($row, |
213 | | - grep { $bki_attr{$_} eq 'bool' } @attnames); |
| 232 | + grep { $bki_attr{$_}{type} eq 'bool' } @attnames); |
214 | 233 | push @{ $schemapg_entries{$table_name} }, '{ ' |
215 | 234 | . join( |
216 | 235 | ', ', grep { defined $_ } |
|
223 | 242 | { |
224 | 243 | $attnum = 0; |
225 | 244 | my @SYS_ATTRS = ( |
226 | | - { ctid => 'tid' }, |
227 | | - { oid => 'oid' }, |
228 | | - { xmin => 'xid' }, |
229 | | - { cmin => 'cid' }, |
230 | | - { xmax => 'xid' }, |
231 | | - { cmax => 'cid' }, |
232 | | - { tableoid => 'oid' }); |
| 245 | + { name => 'ctid', type => 'tid' }, |
| 246 | + { name => 'oid', type => 'oid' }, |
| 247 | + { name => 'xmin', type => 'xid' }, |
| 248 | + { name => 'cmin', type=> 'cid' }, |
| 249 | + { name => 'xmax', type=> 'xid' }, |
| 250 | + { name => 'cmax', type => 'cid' }, |
| 251 | + { name => 'tableoid', type => 'oid' }); |
233 | 252 | foreach my $attr (@SYS_ATTRS) |
234 | 253 | { |
235 | 254 | $attnum--; |
|
326 | 345 | sub emit_pgattr_row |
327 | 346 | { |
328 | 347 | my ($table_name, $attr, $priornotnull) = @_; |
329 | | - my ($attname, $atttype) = %$attr; |
| 348 | + my $attname = $attr->{name}; |
| 349 | + my $atttype = $attr->{type}; |
330 | 350 | my %row; |
331 | 351 |
|
332 | 352 | $row{attrelid} = $catalogs->{$table_name}->{relation_oid}; |
@@ -354,11 +374,20 @@ sub emit_pgattr_row |
354 | 374 | $row{attndims} = $type->{typcategory} eq 'A' ? '1' : '0'; |
355 | 375 | $row{attcollation} = $type->{typcollation}; |
356 | 376 |
|
357 | | - # attnotnull must be set true if the type is fixed-width and |
358 | | - # prior columns are too --- compare DefineAttr in bootstrap.c. |
359 | | - # oidvector and int2vector are also treated as not-nullable. |
360 | | - if ($priornotnull) |
| 377 | + if (defined $attr->{forcenotnull}) |
| 378 | + { |
| 379 | + $row{attnotnull} = 't'; |
| 380 | + } |
| 381 | + elsif (defined $attr->{forcenull}) |
| 382 | + { |
| 383 | + $row{attnotnull} = 'f'; |
| 384 | + } |
| 385 | + elsif ($priornotnull) |
361 | 386 | { |
| 387 | + # attnotnull will automatically be set if the type is |
| 388 | + # fixed-width and prior columns are all NOT NULL --- |
| 389 | + # compare DefineAttr in bootstrap.c. oidvector and |
| 390 | + # int2vector are also treated as not-nullable. |
362 | 391 | $row{attnotnull} = |
363 | 392 | $type->{typname} eq 'oidvector' ? 't' |
364 | 393 | : $type->{typname} eq 'int2vector' ? 't' |
|
0 commit comments