Clarify coding in Catalog::AddDefaultValues.
authorTom Lane
Sat, 15 Feb 2020 20:13:44 +0000 (15:13 -0500)
committerTom Lane
Sat, 15 Feb 2020 20:13:44 +0000 (15:13 -0500)
Make it a bit shorter and better-commented; no functional change.

Alvaro Herrera and Tom Lane

Discussion: https://postgr.es/m/20200212182337[email protected]

src/backend/catalog/Catalog.pm

index c089b1d71dfafd4e2a98503fd537e254f732042e..dd39a086ce4fd7ec59428f80f9ccd895764a8f51 100644 (file)
@@ -331,25 +331,22 @@ sub AddDefaultValues
    foreach my $column (@$schema)
    {
        my $attname = $column->{name};
-       my $atttype = $column->{type};
 
-       if (defined $row->{$attname})
-       {
-           ;
-       }
-       elsif ($attname eq 'oid')
-       {
-           ;
-       }
-       elsif (defined $column->{default})
+       # No work if field already has a value.
+       next if defined $row->{$attname};
+
+       # Ignore 'oid' columns, they're handled elsewhere.
+       next if $attname eq 'oid';
+
+       # If column has a default value, fill that in.
+       if (defined $column->{default})
        {
            $row->{$attname} = $column->{default};
+           next;
        }
-       else
-       {
-           # Failed to find a value.
-           push @missing_fields, $attname;
-       }
+
+       # Failed to find a value for this field.
+       push @missing_fields, $attname;
    }
 
    # Failure to provide all columns is a hard error.