my ($row, $schema, $catname) = @_;
my @missing_fields;
+ # Compute special-case column values.
+ # Note: If you add new cases here, you must also teach
+ # strip_default_values() in include/catalog/reformat_dat_file.pl
+ # to delete them.
+ if ($catname eq 'pg_proc')
+ {
+ # pg_proc.pronargs can be derived from proargtypes.
+ if (defined $row->{proargtypes})
+ {
+ my @proargtypes = split /\s+/, $row->{proargtypes};
+ $row->{pronargs} = scalar(@proargtypes);
+ }
+ }
+
+ # Now fill in defaults, and note any columns that remain undefined.
foreach my $column (@$schema)
{
my $attname = $column->{name};
{
$row->{$attname} = $column->{default};
}
- elsif ($catname eq 'pg_proc'
- && $attname eq 'pronargs'
- && defined($row->{proargtypes}))
- {
- # pg_proc.pronargs can be derived from proargtypes.
- my @proargtypes = split /\s+/, $row->{proargtypes};
- $row->{$attname} = scalar(@proargtypes);
- }
else
{
# Failed to find a value.
}
}
+ # Failure to provide all columns is a hard error.
if (@missing_fields)
{
die sprintf "missing values for field(s) %s in %s.dat line %s\n",
# "convert srctypename to desttypename" for cast functions
# "less-equal-greater" for B-tree comparison functions
+# Note: pronargs is computed when this file is read, so it does not need
+# to be specified in entries here. See AddDefaultValues() in Catalog.pm.
+
# Once upon a time these entries were ordered by OID. Lately it's often
# been the custom to insert new entries adjacent to related older entries.
# Try to do one or the other though, don't just insert entries at random.
close $dat;
}
-# Leave values out if there is a matching default.
+# Remove column values for which there is a matching default,
+# or if the value can be computed from other columns.
sub strip_default_values
{
my ($row, $schema, $catname) = @_;
+ # Delete values that match defaults.
foreach my $column (@$schema)
{
my $attname = $column->{name};
die "strip_default_values: $catname.$attname undefined\n"
if !defined $row->{$attname};
- # Delete values that match defaults.
if (defined $column->{default}
and ($row->{$attname} eq $column->{default}))
{
delete $row->{$attname};
}
+ }
- # Also delete pg_proc.pronargs, since that can be recomputed.
- if ( $catname eq 'pg_proc'
- && $attname eq 'pronargs'
- && defined($row->{proargtypes}))
- {
- delete $row->{$attname};
- }
+ # Delete computed values. See AddDefaultValues() in Catalog.pm.
+ # Note: This must be done after deleting values matching defaults.
+ if ($catname eq 'pg_proc')
+ {
+ delete $row->{pronargs} if defined $row->{proargtypes};
}
}