File: create-schema.sql

package info (click to toggle)
python-stetl 1.0.9%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 89,428 kB
  • ctags: 720
  • sloc: python: 3,527; xml: 699; sql: 428; makefile: 153; sh: 45
file content (27 lines) | stat: -rw-r--r-- 549 bytes parent folder | download | duplicates (6)
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
-- Maak schema aan indien deze nog niet bestaat.
-- Doe niets voor schema 'public'
CREATE OR REPLACE FUNCTION _nlx_createschema(schemaname VARCHAR)
RETURNS void AS
$$
BEGIN

    IF schemaname = 'public' THEN
        RETURN;
    END IF;

    IF NOT EXISTS(
        SELECT schema_name
        FROM information_schema.schemata
        WHERE schema_name = $1
    )
    THEN
        EXECUTE 'CREATE SCHEMA ' || $1 || ';';
    END IF;

END;
$$
LANGUAGE plpgsql;

SELECT _nlx_createschema('{schema}');

DROP FUNCTION _nlx_createschema(schemaname VARCHAR);