CREATE OR REPLACE PROCEDURE prc_load_struct_pas1(IN pschema character varying)
 LANGUAGE plpgsql
AS $procedure$
DECLARE 
  vRec RECORD;
BEGIN
  FOR vRec IN (
    SELECT tablename 
    FROM pg_tables 
    WHERE schemaname = pschema
  ) LOOP
    EXECUTE 'DROP TABLE IF EXISTS '||pschema||'.'||quote_ident(vRec.tablename) || ' CASCADE';
  END LOOP;

  EXECUTE 'CREATE TABLE '||pschema||'.'||'OBJECTS_DDL(obj_type VARCHAR(30), obj_name VARCHAR(99), obj_temp VARCHAR(1), obj_reftable  VARCHAR(30), obj_hashval VARCHAR(64), obj_text TEXT, obj_nivel NUMERIC(5))';
  EXECUTE 'CREATE TABLE '||pschema||'.'||'PUBLIC_DDL (obj_type VARCHAR(30), obj_name VARCHAR(99), obj_temp VARCHAR(1), obj_reftable  VARCHAR(30), obj_hashval VARCHAR(64), obj_text TEXT, obj_nivel NUMERIC(5))';
  -- am probleme cu primary key findca se repeta unele functii
  --EXECUTE 'ALTER TABLE '||pschema||'.'||'OBJECTS_DDL ADD CONSTRAINT PK_OBJECTS_DDL PRIMARY KEY ( obj_type, obj_name )';
  EXECUTE 'CREATE TABLE '||pschema||'.'||'DATE_HASH(obj_name VARCHAR(99), obj_hashval VARCHAR(64), obj_linecount NUMERIC(20))';
  --EXECUTE 'ALTER TABLE  '||pschema||'.'||'DATE_HASH ADD CONSTRAINT PK_DATE_HASH PRIMARY KEY ( obj_name )';
  --EXECUTE 'CREATE TABLE '||pschema||'.'||'STRUCT_XML(table_owner VARCHAR(30), table_name VARCHAR(99), table_data XML, table_nivel NUMERIC(5))';
end;
$procedure$
