Schema
Owner
postgres
Descriptions
There is no description for function _updaterastersrid
Options
Option | Value |
---|---|
Returns |
boolean |
Language |
|
Parameters |
schema_name name table_name name column_name name new_srid integer |
Definition
CREATE OR REPLACE FUNCTION public._updaterastersrid (
schema_name name,
table_name name,
column_name name,
new_srid integer
)
RETURNS boolean AS
$span$
DECLARE
fqtn text;
schema name;
sql text;
srid integer;
ct boolean;
BEGIN
-- validate schema
schema := NULL;
IF length($1) > 0 THEN
sql := 'SELECT nspname FROM pg_namespace '
|| 'WHERE nspname = ' || quote_literal($1)
|| 'LIMIT 1';
EXECUTE sql INTO schema;
IF schema IS NULL THEN
RAISE EXCEPTION 'The value provided for schema is invalid';
RETURN FALSE;
END IF;
END IF;
IF schema IS NULL THEN
sql := 'SELECT n.nspname AS schemaname '
|| 'FROM pg_catalog.pg_class c '
|| 'JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace '
|| 'WHERE c.relkind = ' || quote_literal('r')
|| ' AND n.nspname NOT IN (' || quote_literal('pg_catalog')
|| ', ' || quote_literal('pg_toast')
|| ') AND pg_catalog.pg_table_is_visible(c.oid)'
|| ' AND c.relname = ' || quote_literal($2);
EXECUTE sql INTO schema;
IF schema IS NULL THEN
RAISE EXCEPTION 'The table % does not occur in the search_path', quote_literal($2);
RETURN FALSE;
END IF;
END IF;
-- clamp SRID
IF new_srid < 0 THEN
srid := ST_SRID('POINT EMPTY'::geometry);
RAISE NOTICE 'SRID % converted to the officially unknown SRID %', new_srid, srid;
ELSE
srid := new_srid;
END IF;
-- drop coverage tile constraint
-- done separately just in case constraint doesn't exist
ct := _raster_constraint_info_coverage_tile(schema, $2, $3);
IF ct IS TRUE THEN
PERFORM _drop_raster_constraint_coverage_tile(schema, $2, $3);
END IF;
-- drop SRID, extent, alignment constraints
PERFORM DropRasterConstraints(schema, $2, $3, 'extent', 'alignment', 'srid');
fqtn := '';
IF length($1) > 0 THEN
fqtn := quote_ident($1) || '.';
END IF;
fqtn := fqtn || quote_ident($2);
-- update SRID
sql := 'UPDATE ' || fqtn ||
' SET ' || quote_ident($3) ||
' = ST_SetSRID(' || quote_ident($3) ||
'::raster, ' || srid || ')';
RAISE NOTICE 'sql = %', sql;
EXECUTE sql;
-- add SRID constraint
PERFORM AddRasterConstraints(schema, $2, $3, 'srid', 'extent', 'alignment');
-- add coverage tile constraint if needed
IF ct IS TRUE THEN
PERFORM _add_raster_constraint_coverage_tile(schema, $2, $3);
END IF;
RETURN TRUE;
END;
$span$
LANGUAGE 'plpgsql'
VOLATILE
CALLED ON NULL INPUT
SECURITY INVOKER
COST 100;
This file was generated with SQL Manager for PostgreSQL (www.pgsqlmanager.com) at 13/03/2014 13:23 |