pggeodb.nancy.inra.fr/db_robot - db_robot on pggeodb.nancy.inra.fr
Previous topic Chapter index Next topic

Function: _add_raster_constraint_pixel_types

 

 

Schema

public

 

Owner

albenard

 

Descriptions

There is no description for function _add_raster_constraint_pixel_types

 

Options

Option

Value

Returns

boolean

Language

plpgsql

Parameters

rastschema name

rasttable name

rastcolumn name

 

Definition

CREATE OR REPLACE FUNCTION public._add_raster_constraint_pixel_types (
 rastschema name,
 rasttable name,
 rastcolumn name
)
RETURNS boolean AS
$span$
DECLARE

fqtn text;
cn name;
sql text;
attr text[];
max int;
BEGIN
fqtn := '';
IF length($1) > 0 THEN
fqtn := quote_ident($1) || '.';
END IF;
fqtn := fqtn || quote_ident($2);

cn := 'enforce_pixel_types_' || $3;

sql := 'SELECT public._raster_constraint_pixel_types(' || quote_ident($3)
|| ') FROM ' || fqtn
|| ' LIMIT 1';
BEGIN
EXECUTE
sql INTO attr;
EXCEPTION WHEN OTHERS THEN
RAISE NOTICE
'Unable to get the pixel types of a sample raster: % (%)',
       SQLERRM, SQLSTATE;
RETURN FALSE;
END;
max := array_length(attr, 1);
IF max < 1 OR max IS NULL THEN
RAISE NOTICE
'Unable to get the pixel types of a sample raster (max < 1 or null)';
RETURN FALSE;
END IF;

sql := 'ALTER TABLE ' || fqtn
|| ' ADD CONSTRAINT ' || quote_ident(cn)
|| ' CHECK (_raster_constraint_pixel_types(' || quote_ident($3)
|| ') = ''{';
FOR x in 1..max LOOP
sql := sql || '"' || attr[x] || '"';
IF x < max THEN
sql := sql || ',';
END IF;
END LOOP;
sql := sql || '}''::text[])';

RETURN  public._add_raster_constraint(cn, sql);
END;
$span$
LANGUAGE
'plpgsql'
VOLATILE
RETURNS NULL ON NULL INPUT
SECURITY INVOKER
COST
100;

This file was generated with SQL Manager for PostgreSQL (www.pgsqlmanager.com) at 26/02/2014 11:51
Previous topic Chapter index Next topic