6
6
* delete_feature(pid_array bigint[]) RETURNS SETOF BIGINT
7
7
* delete_feature(pid_array bigint[], schema_name TEXT) RETURNS SETOF BIGINT
8
8
* delete_feature(pid bigint, schema_name TEXT) RETURNS BIGINT
9
+ * delete_property_row(pid_array bigint[]) RETURNS SETOF BIGINT
9
10
* delete_property(pid_array bigint[]) RETURNS SETOF BIGINT
10
11
* delete_property(pid_array bigint[], schema_name TEXT) RETURNS SETOF BIGINT
11
12
* delete_property(pid bigint, schema_name TEXT) RETURNS BIGINT
@@ -70,7 +71,7 @@ DECLARE
70
71
deleted_ids bigint [] := ' {}' ;
71
72
BEGIN
72
73
PERFORM
73
- citydb_pkg .delete_property (array_agg(p .id ))
74
+ citydb_pkg .delete_property_row (array_agg(p .id ))
74
75
FROM
75
76
property p,
76
77
unnest($1 ) a(a_id)
@@ -131,9 +132,9 @@ $body$
131
132
LANGUAGE plpgsql STRICT;
132
133
133
134
/* *****************************************************************
134
- * delete from PROPERTY table based on an id array
135
+ * delete single row from PROPERTY table based on an id array
135
136
******************************************************************/
136
- CREATE OR REPLACE FUNCTION citydb_pkg .delete_property (bigint []) RETURNS SETOF BIGINT AS
137
+ CREATE OR REPLACE FUNCTION citydb_pkg .delete_property_row (bigint []) RETURNS SETOF BIGINT AS
137
138
$body$
138
139
DECLARE
139
140
deleted_ids bigint [] := ' {}' ;
@@ -143,13 +144,13 @@ DECLARE
143
144
appearance_ids bigint [] := ' {}' ;
144
145
address_ids bigint [] := ' {}' ;
145
146
BEGIN
146
- WITH child_refs AS (
147
+ WITH property_ids AS (
147
148
DELETE FROM
148
149
property p
149
150
USING
150
151
unnest($1 ) a(a_id)
151
152
WHERE
152
- p .root_id = a .a_id
153
+ p .id = a .a_id
153
154
RETURNING
154
155
p .id ,
155
156
p .val_feature_id ,
@@ -174,7 +175,7 @@ BEGIN
174
175
appearance_ids,
175
176
address_ids
176
177
FROM
177
- child_refs
178
+ property_ids
178
179
WHERE
179
180
val_feature_id IS NULL OR val_reference_type IS NULL OR val_reference_type = 1 ;
180
181
@@ -223,6 +224,46 @@ END;
223
224
$body$
224
225
LANGUAGE plpgsql STRICT;
225
226
227
+ /* *****************************************************************
228
+ * delete from PROPERTY table based on an id array
229
+ ******************************************************************/
230
+ CREATE OR REPLACE FUNCTION citydb_pkg .delete_property(bigint []) RETURNS SETOF BIGINT AS
231
+ $body$
232
+ DECLARE
233
+ property_ids bigint [] := ' {}' ;
234
+ BEGIN
235
+ WITH RECURSIVE child_refs AS (
236
+ SELECT
237
+ p .id
238
+ FROM
239
+ property p,
240
+ unnest($1 ) a(a_id)
241
+ WHERE
242
+ p .id = a .a_id
243
+ UNION ALL
244
+ SELECT
245
+ p .id
246
+ FROM
247
+ property p,
248
+ child_refs c
249
+ WHERE
250
+ p .parent_id = c .id
251
+ )
252
+ SELECT
253
+ array_agg(id)
254
+ INTO
255
+ property_ids
256
+ FROM
257
+ child_refs;
258
+
259
+ RETURN QUERY
260
+ SELECT citydb_pkg .delete_property_row (property_ids)
261
+ INTERSECT
262
+ SELECT unnest($1 );
263
+ END;
264
+ $body$
265
+ LANGUAGE plpgsql STRICT;
266
+
226
267
/* *****************************************************************
227
268
* delete from PROPERTY table based on an id array and schema name
228
269
******************************************************************/
0 commit comments