 
 -- Enable PostGIS (includes raster)
 CREATE EXTENSION IF NOT EXISTS postgis; 
+
+-- Enable Encryption
+CREATE EXTENSION pgcrypto;
 
 -- Drop Spatial Tables (comment this section out if you have built your spatial tables once)
 -- To comment use: ' -- '

      dynamic_where2 := '(' || array_to_string(built_where, ' OR ') || ')';
	
    END IF;
   
    -- create dynamic paging statment
    IF $5 IS NOT NULL AND $5 <> '' THEN
      IF paging_statement IS NOT NULL THEN
        paging_statement := paging_statement || 'ORDER BY ' || $5 || ' ';
      ELSE
        paging_statement := ' ORDER BY ' || $5 || ' ';
      END IF;
    END IF;		    
    IF $6 IS NOT NULL AND $6 > 0 THEN
      IF paging_statement IS NOT NULL THEN
        paging_statement := paging_statement || 'LIMIT ' || $6 || ' ';
      ELSE
        paging_statement := ' LIMIT ' || $6 || ' ';
      END IF;
    END IF;		
    IF $7 IS NOT NULL AND $7 > 0 THEN
      IF paging_statement IS NOT NULL THEN
        paging_statement := paging_statement || 'OFFSET ' || $7 || ' ';
      ELSE
        paging_statement := ' OFFSET ' || $7 || ' ';
      END IF;      
    END IF;	


      dynamic_where2 := '(' || array_to_string(built_where, ' OR ') || ')';
	
    END IF;

    -- filter by date range
    IF ($4 is not null AND $5 is not null) THEN
	dynamic_where1 := array_append(dynamic_where1, '(start_date > ''' || $4 || ''' AND end_date < ''' || $5 || ''')');
    END IF;
   
    -- prepare statement																
    RAISE NOTICE '   + First where statement: %', array_to_string(dynamic_where1, ' AND ');
