File: create_extension_unpackage.pl

package info (click to toggle)
postgis 3.3.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 87,748 kB
  • sloc: ansic: 158,671; sql: 91,546; xml: 54,004; cpp: 12,339; sh: 5,187; perl: 5,100; makefile: 3,085; python: 1,205; yacc: 447; lex: 151; javascript: 6
file content (43 lines) | stat: -rwxr-xr-x 981 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env perl

#
# PostGIS - Spatial Types for PostgreSQL
# http://postgis.net
#
# Copyright (C) 2017 Sandro Santilli <strk@kbt.io>
#
# This is free software; you can redistribute and/or modify it under
# the terms of the GNU General Public Licence. See the COPYING file.
#

use warnings;
use strict;
use POSIX 'strftime';

eval "exec perl -w $0 $@"
	if (0);


die "Usage: perl $0 <extname> [<sqlfile>]\n"
  . "  Prints SQL to drop objects dropped by given SQL file\n"
  . "  from extension with given name.\n"
unless @ARGV;

my $extname = shift(@ARGV);

while(<>)
{
  /^DROP/i or next;
  s/ IF EXISTS//i;
  s/ CASCADE//i;
  chop;
  print 'DO $$ BEGIN ALTER EXTENSION ' . $extname
    . ' ' . $_ . 'EXCEPTION '
    . 'WHEN object_not_in_prerequisite_state OR undefined_function OR undefined_object THEN '
    . " RAISE NOTICE '%', SQLERRM; "
    . 'WHEN OTHERS THEN '
    . " RAISE EXCEPTION 'Got % - %', SQLSTATE, SQLERRM; "
    . 'END $$ LANGUAGE ' . "'plpgsql';\n";
}

1;