x
1
DECLARE
2
myrec RECORD;
3
okay boolean;
4
real_schema name;
5
6
BEGIN
7
8
-- Find, check or fix schema_name
9
IF ( schema_name != '' ) THEN
10
okay = false;
11
12
FOR myrec IN SELECT nspname FROM pg_namespace WHERE text(nspname) = schema_name LOOP
13
okay := true;
14
END LOOP;
15
16
IF ( okay <> true ) THEN
17
RAISE NOTICE 'Invalid schema name - using current_schema()';
18
SELECT current_schema() into real_schema;
19
ELSE
20
real_schema = schema_name;
21
END IF;
22
ELSE
23
SELECT current_schema() into real_schema;
24
END IF;
25
26
-- Find out if the column is in the geometry_columns table
27
okay = false;
28
FOR myrec IN SELECT * from public.geometry_columns where f_table_schema = text(real_schema) and f_table_name = table_name and f_geometry_column = column_name LOOP
29
okay := true;
30
END LOOP;
31
IF (okay <> true) THEN
32
RAISE EXCEPTION 'column not found in geometry_columns table';
33
RETURN false;
34
END IF;
35
36
-- Remove table column
37
EXECUTE 'ALTER TABLE ' || quote_ident(real_schema) || '.' ||
38
quote_ident(table_name) || ' DROP COLUMN ' ||
39
quote_ident(column_name);
40
41
RETURN real_schema || '.' || table_name || '.' || column_name ||' effectively removed.';
42
43
END;