1
# perl create_undef.pl <postgis.sql>
2
# creates a new sql script to delete all the postgis functions et al.
4
($#ARGV == 1) || die "Usage: perl create_undef.pl <postgis.sql> <pgsql_version #>\nCreates a new SQL script to delete all the PostGIS functions.\n";
6
# drops are in the following order:
7
# 1. Indexing system stuff
8
# 2. Meta datatables <not done>
22
my $version = $ARGV[1];
26
if ( $version ge "73" )
28
print "-- Drop index bindings from system tables\n";
29
print "DROP OPERATOR CLASS gist_geometry_ops USING gist CASCADE;\n";
33
print "-- Drop index bindings from system tables\n";
34
print "DELETE FROM pg_amproc WHERE amopclaid = (SELECT oid FROM pg_opclass WHERE opcname = 'gist_geometry_ops');\n";
35
print "DELETE FROM pg_amop WHERE amopclaid = (SELECT oid FROM pg_opclass WHERE opcname = 'gist_geometry_ops');\n";
36
print "DELETE FROM pg_opclass WHERE opcname = 'gist_geometry_ops';\n";
40
open( INPUT, $ARGV[0] ) || die "Couldn't open file: $ARGV[0]\n";
42
while( my $line = <INPUT>)
45
push (@funcs, $line) if ($line =~ /^create function/i);
46
push (@funcs, $line) if ($line =~ /^create or replace function/i);
47
push (@ops, $line) if ($line =~ /^create operator.*\(/i);
48
push (@aggs, $line) if ($line =~ /^create aggregate/i);
49
push (@types, $line) if ($line =~ /^create type/i);
50
push (@casts, $line) if ($line =~ /^create cast/i);
55
print "-- Drop all aggregates.\n";
57
foreach my $agg (@aggs)
59
if ( $agg =~ /create aggregate\s*(\w+)\s*\(/i )
61
if ( $version eq "71" )
63
print "DROP AGGREGATE $1 geometry;\n";
67
print "DROP AGGREGATE $1 ( geometry );\n";
72
die "Couldn't parse line: $agg\n";
76
print "-- Drop all operators.\n";
80
if ($op =~ /create operator ([^(]+)/i )
82
if ( $version ge "73" )
84
print "DROP OPERATOR $1 (geometry,geometry) CASCADE;\n";
88
print "DROP OPERATOR $1 (geometry,geometry);\n";
93
die "Couldn't parse line: $op\n";
98
print "-- Drop all casts.\n";
100
foreach my $cast (@casts)
102
if ($cast =~ /create cast\s*\((.+?)\)/i )
104
print "DROP CAST ($1);\n";
108
die "Couldn't parse line: $cast\n";
112
print "-- Drop all functions.\n";
114
foreach my $fn (@funcs)
116
if ($fn =~ /.* function ([^(]+)\((.*)\)/i )
121
if ( $version ge "73" )
123
if ( ! ( $fn_nm =~ /_in/i || $fn_nm =~ /_out/i || $fn_nm =~ /_recv/i || $fn_nm =~ /_send/i || $fn_nm =~ /_analyze/i ) )
125
print "DROP FUNCTION $fn_nm ($fn_arg) CASCADE;\n";
130
print "DROP FUNCTION $fn_nm ($fn_arg);\n";
135
die "Couldn't parse line: $fn\n";
139
print "-- Drop all types.\n";
141
foreach my $type (@types)
143
if ($type =~ /create type ([^(]+)/i )
145
if ( $version ge "73" )
147
print "DROP TYPE $1 CASCADE;\n";
151
print "DROP TYPE $1;\n";
156
die "Couldn't parse line: $type\n";
160
print "-- Drop all tables.\n";
161
print "DROP TABLE spatial_ref_sys;\n";
162
print "DROP TABLE geometry_columns;\n";