[postgis-tickets] [SCM] PostGIS branch master updated. 3.3.0rc2-327-gdbd2b5f81
git at osgeo.org
git at osgeo.org
Tue Nov 8 08:37:06 PST 2022
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".
The branch, master has been updated
via dbd2b5f819afd76322f0becd6e559d1ce4190f68 (commit)
via e34553495fda3f3b005a33349dc19ffa50d4724a (commit)
from bb4786f3ed3c9966635e0ea9c6f410a5058b64fe (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit dbd2b5f819afd76322f0becd6e559d1ce4190f68
Author: Sandro Santilli <strk at kbt.io>
Date: Tue Nov 8 17:33:06 2022 +0100
RenameTopoGeometryColumn function
Closes #5286.
Includes docs and regress test
diff --git a/NEWS b/NEWS
index d03b84bfd..48d3b44ef 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ xxxx/xx/xx
- #5257, #5261, #5277, Support changes for PostgreSQL 16 (Regina Obe)
- #5006, GH705, ST_Transform: Support PROJ pipelines (Robert Coup, Koordinates)
- #5283, RenameTopology (Sandro Santilli)
+ - #5286, RenameTopoGeometryColumn (Sandro Santilli)
* Enhancements *
- #5194, do not update system catalogs from postgis_extensions_upgrade (Sandro Santilli)
diff --git a/doc/extras_topology.xml b/doc/extras_topology.xml
index 062bf9393..3e865a854 100644
--- a/doc/extras_topology.xml
+++ b/doc/extras_topology.xml
@@ -353,6 +353,56 @@ SELECT topology.AddTopoGeometryColumn('ri_topo', 'ri', 'roads', 'topo', 'LINE');
</para>
</refsection>
</refentry>
+ <refentry id="RenameTopoGeometryColumn">
+ <refnamediv>
+ <refname>RenameTopoGeometryColumn</refname>
+ <refpurpose>Renames a topogeometry column</refpurpose>
+ </refnamediv>
+
+ <refsynopsisdiv>
+ <funcsynopsis>
+ <funcprototype>
+ <funcdef>topology.layer <function>RenameTopoGeometryColumn</function></funcdef>
+ <paramdef><type>regclass </type>
+ <parameter>layer_table</parameter></paramdef>
+ <paramdef><type>name </type>
+ <parameter>feature_column</parameter></paramdef>
+ <paramdef><type>name </type>
+ <parameter>new_name</parameter></paramdef>
+ </funcprototype>
+ </funcsynopsis>
+ </refsynopsisdiv>
+
+ <refsection>
+ <title>Description</title>
+
+ <para>
+This function changes the name of an existing TopoGeometry column
+ensuring metadata information about it is updated accordingly.
+ </para>
+
+ <!-- use this format if new function -->
+ <para>Availability: 3.4.0</para>
+
+ </refsection>
+
+ <refsection>
+ <title>Examples</title>
+ <programlisting>
+SELECT topology.RenameTopoGeometryColumn('public.parcels', 'topogeom', 'tgeom');
+ </programlisting>
+ </refsection>
+
+ <!-- Optionally add a "See Also" section -->
+ <refsection>
+ <title>See Also</title>
+
+ <para>
+ <xref linkend="AddTopoGeometryColumn"/>,
+ <xref linkend="RenameTopology"/>
+ </para>
+ </refsection>
+ </refentry>
<refentry id="DropTopology">
<refnamediv>
<refname>DropTopology</refname>
@@ -437,7 +487,8 @@ This example renames a topology from <varname>topo_stage</varname> to
<title>See Also</title>
<para>>
- <xref linkend="CopyTopology" />
+ <xref linkend="CopyTopology" />,
+ <xref linkend="RenameTopoGeometryColumn" />
</para>
</refsection>
</refentry>
diff --git a/topology/sql/manage/RenameTopoGeometryColumn.sql.in b/topology/sql/manage/RenameTopoGeometryColumn.sql.in
new file mode 100644
index 000000000..512549210
--- /dev/null
+++ b/topology/sql/manage/RenameTopoGeometryColumn.sql.in
@@ -0,0 +1,75 @@
+-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+--
+--
+-- PostGIS - Spatial Types for PostgreSQL
+-- http://postgis.net
+--
+-- Copyright (C) 2022 Sandro Santilli <strk at kbt.io>
+--
+-- This is free software; you can redistribute and/or modify it under
+-- the terms of the GNU General Public Licence. See the COPYING file.
+--
+-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+--{
+-- RenameTopoGeometryColumn(regclass, old_colname, new_colname)
+--
+-- Rename a TopoGeometry column in a table.
+-- Returns the new topology.layer record
+--
+-- Availability: 3.4.0
+--
+CREATE OR REPLACE FUNCTION topology.RenameTopoGeometryColumn(layer_table regclass, feature_column name, new_name name)
+ RETURNS topology.layer
+AS
+$$
+DECLARE
+ layer topology.layer;
+ sql text;
+BEGIN
+
+ layer := topology.FindLayer(layer_table, feature_column);
+ IF layer IS NULL THEN
+ RAISE EXCEPTION 'Layer %.% does not exist', layer_table, feature_column;
+ END IF;
+
+ --
+ -- Rename TopoGeometry column
+ --
+ sql := format('ALTER TABLE %s RENAME %I to %I',
+ layer_table, feature_column, new_name);
+ EXECUTE sql;
+
+ -- Update topology.layer record
+
+ -- Temporarely disable integrity check
+ ALTER TABLE topology.layer DISABLE TRIGGER layer_integrity_checks;
+
+ sql := format(
+ 'UPDATE topology.layer SET feature_column = %L '
+ 'WHERE topology_id = $1 and layer_id = $2',
+ new_name
+ );
+ EXECUTE sql USING layer.topology_id, layer.layer_id;
+
+ -- Re-enable integrity check
+ -- TODO: tweak layer_integrity_checks to allow this
+ ALTER TABLE topology.layer ENABLE TRIGGER layer_integrity_checks;
+
+ --
+ -- Rename constraints on TopoGeom column
+ --
+ sql := format(
+ 'ALTER TABLE %s RENAME CONSTRAINT '
+ '"check_topogeom_%s" TO "check_topogeom_%s"',
+ layer_table, feature_column, new_name
+ );
+ EXECUTE sql;
+
+ layer.feature_column = new_name;
+ RETURN layer;
+END;
+$$
+LANGUAGE 'plpgsql' VOLATILE;
+--} RenameTopoGeometryColumn
+
diff --git a/topology/test/regress/renametopogeometrycolumn.sql b/topology/test/regress/renametopogeometrycolumn.sql
new file mode 100644
index 000000000..e78b6f93a
--- /dev/null
+++ b/topology/test/regress/renametopogeometrycolumn.sql
@@ -0,0 +1,8 @@
+BEGIN;
+SELECT NULL FROM createtopology('tt');
+CREATE TABLE tt.f(id integer);
+SELECT NULL FROM addtopogeometrycolumn('tt','tt','f','tg','POINT');
+SELECT 't0', layer_id, feature_column FROM topology.layer;
+SELECT 't1', layer_id, feature_column FROM renametopogeometrycolumn('tt.f', 'tg', 'the TopoGeom');
+SELECT 't2', layer_id, feature_column FROM renametopogeometrycolumn('tt.f', 'the TopoGeom', 'tgeom');
+ROLLBACK;
diff --git a/topology/test/regress/renametopogeometrycolumn_expected b/topology/test/regress/renametopogeometrycolumn_expected
new file mode 100644
index 000000000..68362fb59
--- /dev/null
+++ b/topology/test/regress/renametopogeometrycolumn_expected
@@ -0,0 +1,3 @@
+t0|1|tg
+t1|1|the TopoGeom
+t2|1|tgeom
diff --git a/topology/test/tests.mk b/topology/test/tests.mk
index 98712c40d..3ba97b59b 100644
--- a/topology/test/tests.mk
+++ b/topology/test/tests.mk
@@ -46,8 +46,9 @@ TESTS += \
$(top_srcdir)/topology/test/regress/legacy_query.sql \
$(top_srcdir)/topology/test/regress/legacy_validate.sql \
$(top_srcdir)/topology/test/regress/polygonize.sql \
- $(top_srcdir)/topology/test/regress/renametopology.sql \
$(top_srcdir)/topology/test/regress/removeunusedprimitives.sql \
+ $(top_srcdir)/topology/test/regress/renametopology.sql \
+ $(top_srcdir)/topology/test/regress/renametopogeometrycolumn.sql \
$(top_srcdir)/topology/test/regress/sqlmm.sql \
$(top_srcdir)/topology/test/regress/st_addedgemodface.sql \
$(top_srcdir)/topology/test/regress/st_addedgenewfaces.sql \
diff --git a/topology/topology.sql.in b/topology/topology.sql.in
index 197f72274..1160c58fe 100644
--- a/topology/topology.sql.in
+++ b/topology/topology.sql.in
@@ -1410,6 +1410,7 @@ LANGUAGE 'plpgsql' VOLATILE STRICT;
--general management --
#include "sql/manage/ManageHelper.sql.in"
#include "sql/manage/AddTopoGeometryColumn.sql.in"
+#include "sql/manage/RenameTopoGeometryColumn.sql.in"
#include "sql/manage/CreateTopology.sql.in"
#include "sql/manage/TopologySummary.sql.in"
#include "sql/manage/CopyTopology.sql.in"
commit e34553495fda3f3b005a33349dc19ffa50d4724a
Author: Sandro Santilli <strk at kbt.io>
Date: Tue Nov 8 17:05:46 2022 +0100
Add missing sql/manage/ dependencies on topology.sql
diff --git a/topology/Makefile.in b/topology/Makefile.in
index fc6ffefd4..89dc31e00 100644
--- a/topology/Makefile.in
+++ b/topology/Makefile.in
@@ -134,14 +134,16 @@ topology.sql: \
sql/query/GetRingEdges.sql.in \
sql/query/GetNodeEdges.sql.in \
sql/query/GetFaceContainingPoint.sql.in \
- sql/manage/TopologySummary.sql.in \
+ sql/manage/AddTopoGeometryColumn.sql.in \
sql/manage/CopyTopology.sql.in \
+ sql/manage/CreateTopology.sql.in \
sql/manage/FindLayer.sql.in \
sql/manage/FindTopology.sql.in \
sql/manage/ManageHelper.sql.in \
sql/manage/RenameTopology.sql.in \
- sql/manage/ValidateTopology.sql.in \
+ sql/manage/TopologySummary.sql.in \
sql/manage/ValidateTopologyRelation.sql.in \
+ sql/manage/ValidateTopology.sql.in \
sql/topoelement/topoelement_agg.sql.in \
sql/topogeometry/type.sql.in \
sql/topogeometry/totopogeom.sql.in \
-----------------------------------------------------------------------
Summary of changes:
NEWS | 1 +
doc/extras_topology.xml | 53 ++++++++++++++-
topology/Makefile.in | 6 +-
.../sql/manage/RenameTopoGeometryColumn.sql.in | 75 ++++++++++++++++++++++
topology/test/regress/renametopogeometrycolumn.sql | 8 +++
.../test/regress/renametopogeometrycolumn_expected | 3 +
topology/test/tests.mk | 3 +-
topology/topology.sql.in | 1 +
8 files changed, 146 insertions(+), 4 deletions(-)
create mode 100644 topology/sql/manage/RenameTopoGeometryColumn.sql.in
create mode 100644 topology/test/regress/renametopogeometrycolumn.sql
create mode 100644 topology/test/regress/renametopogeometrycolumn_expected
hooks/post-receive
--
PostGIS
More information about the postgis-tickets
mailing list