--- /home/john/pgdev/postgresql/src/include/catalog/reformat_dat_files.pl 2018-03-27 18:04:54.698464144 +0700 +++ remove_pg_type_oid_symbols.pl 2018-03-27 18:13:42.270611897 +0700 @@ -1,18 +1,12 @@ #!/usr/bin/perl -w #---------------------------------------------------------------------- # -# reformat_dat_files.pl -# Perl script that reads in a catalog data file and writes out -# a functionally equivalent file in a standard format. -# -# Metadata entries (if any) come first, with normal attributes -# starting on the following line, in the same order they would be in -# the actual table. +# remove_pg_type_oid_symbols.pl # # Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group # Portions Copyright (c) 1994, Regents of the University of California # -# /src/include/catalog/reformat_dat_files.pl +# /src/include/catalog/remove_pg_type_oid_symbols.pl # #---------------------------------------------------------------------- @@ -85,22 +79,6 @@ $catalog_data{$catname} = Catalog::ParseData($datfile, $schema, 1); } -######################################################################## -# At this point, we have read all the data. If you are modifying this -# script for bulk editing, this is a good place to build lookup tables, -# if you need to. In the following example, the "next if !ref $row" -# check below is a hack to filter out non-hash objects. This is because -# we build the lookup tables from data that we read using the -# "preserve_formatting" parameter. -# -##Index access method lookup. -#my %amnames; -#foreach my $row (@{ $catalog_data{pg_am} }) -#{ -# next if !ref $row; -# $amnames{$row->{oid}} = $row->{amname}; -#} -######################################################################## # Write the data. foreach my $catname (@catnames) @@ -131,10 +109,15 @@ my %values = %$data; ############################################################ - # At this point we have the full tuple in memory as a hash - # and can do any operations we want. As written, it only - # removes default values, but this script can be adopted to - # do one-off bulk-editing. + # Remove pg_type OID symbols if they can match the rule + # we use to generate them. + if ($catname eq 'pg_type' and exists $values{oid_symbol}) + { + my $symbol = form_pg_type_symbol($values{typname}); + delete $values{oid_symbol} + if defined $symbol + and $values{oid_symbol} eq $symbol; + } ############################################################ if (!$full_tuples) @@ -181,6 +164,26 @@ } } +######################################################################## +# Determine canonical pg_type OID #define symbol from the type name. +sub form_pg_type_symbol +{ + my $typename = shift; + + # Skip for rowtypes of bootstrap tables. + return + if $typename eq 'pg_type' + or $typename eq 'pg_proc' + or $typename eq 'pg_attribute' + or $typename eq 'pg_class'; + + $typename =~ /(_)?(.+)/; + my $arraystr = $1 ? 'ARRAY' : ''; + my $name = uc $2; + return $name . $arraystr . 'OID'; +} +######################################################################## + # Leave values out if there is a matching default. sub strip_default_values {