URX_PUBLIC._add_raster_constraint_alignment(rastschema name, rasttable name, rastcolumn name) - Procedure
Home|Tables|Schemas|Diagrams|Foreign Keys|Indexes

NameURX_PUBLIC._add_raster_constraint_alignment(rastschema name, rasttable name, rastcolumn name)
Comment
Src
CREATE FUNCTION "URX_PUBLIC"."_add_raster_constraint_alignment"(rastschema name, rasttable name, rastcolumn name) 
 RETURNS boolean AS 
$BODY$
	DECLARE
		fqtn text;
		cn name;
		sql text;
		attr text;
	BEGIN
		fqtn := '';
		IF length($1) > 0 THEN
			fqtn := quote_ident($1) || '.';
		END IF;
		fqtn := fqtn || quote_ident($2);

		cn := 'enforce_same_alignment_' || $3;

		sql := 'SELECT "URX_PUBLIC".st_makeemptyraster(1, 1, upperleftx, upperlefty, scalex, scaley, skewx, skewy, srid) FROM "URX_PUBLIC".st_metadata((SELECT '
			|| quote_ident($3)
			|| ' FROM ' || fqtn || ' LIMIT 1))';
		BEGIN
			EXECUTE sql INTO attr;
		EXCEPTION WHEN OTHERS THEN
			RAISE NOTICE 'Unable to get the alignment of a sample raster: % (%)',
        SQLERRM, SQLSTATE;
			RETURN FALSE;
		END;

		sql := 'ALTER TABLE ' || fqtn ||
			' ADD CONSTRAINT ' || quote_ident(cn) ||
			' CHECK (st_samealignment(' || quote_ident($3) || ', ''' || attr || '''::raster))';
		RETURN  "URX_PUBLIC"._add_raster_constraint(cn, sql);
	END;
	$BODY$
 LANGUAGE 'plpgsql' VOLATILESTRICT ;