Project

General

Profile

« Previous | Next » 

Revision 13488

schemas/util.sql: save_drop_views()/restore_views(): use opaque return type so it can be changed without changing the local var type in functions that use this

View differences:

trunk/schemas/util.sql
72 72

  
73 73

  
74 74
--
75
-- Name: restore_views_info; Type: TYPE; Schema: util; Owner: -
76
--
77

  
78
CREATE TYPE restore_views_info AS (
79
	recreate_cmds text[]
80
);
81

  
82

  
83
--
75 84
-- Name: %==(anyelement, anyelement); Type: FUNCTION; Schema: util; Owner: -
76 85
--
77 86

  
......
1805 1814
    AS $_$
1806 1815
DECLARE
1807 1816
	PG_EXCEPTION_DETAIL text;
1808
	restore_views_info text[] = util.save_drop_views(users);
1817
	restore_views_info util.restore_views_info;
1809 1818
BEGIN
1819
	restore_views_info = util.save_drop_views(users);
1810 1820
	PERFORM util.eval(cmd);
1811 1821
	PERFORM util.restore_views(restore_views_info);
1812 1822
EXCEPTION
......
3303 3313

  
3304 3314

  
3305 3315
--
3306
-- Name: restore_views(text[]); Type: FUNCTION; Schema: util; Owner: -
3316
-- Name: restore_views(restore_views_info); Type: FUNCTION; Schema: util; Owner: -
3307 3317
--
3308 3318

  
3309
CREATE FUNCTION restore_views(views text[]) RETURNS void
3319
CREATE FUNCTION restore_views(restore_views_info) RETURNS void
3310 3320
    LANGUAGE sql
3311 3321
    AS $_$
3312 3322
SELECT util.debug_print_var('views', $1);
3313 3323
SELECT util.create_if_not_exists(recreate_cmd)
3314
FROM unnest($1) recreate_cmd; -- in forward dependency order
3324
FROM unnest($1.recreate_cmds) recreate_cmd; -- in forward dependency order
3315 3325
	/* create_if_not_exists() rather than eval(), because cmd might manually
3316 3326
	re-create a deleted dependent view, causing it to already exist */
3317 3327
SELECT NULL::void; -- don't fold away functions called in previous query
......
3381 3391
-- Name: save_drop_views(text[]); Type: FUNCTION; Schema: util; Owner: -
3382 3392
--
3383 3393

  
3384
CREATE FUNCTION save_drop_views(views text[]) RETURNS text[]
3394
CREATE FUNCTION save_drop_views(views text[]) RETURNS restore_views_info
3385 3395
    LANGUAGE sql
3386 3396
    AS $_$
3387
SELECT /*return in forward dependency order*/util.array_reverse(array(
3397
SELECT ROW(/*return in forward dependency order*/util.array_reverse(array(
3388 3398
SELECT util.save_drop_view(view_)
3389 3399
FROM unnest(/*drop in reverse dependency order*/util.array_reverse($1)) view_
3390
))
3400
)))::util.restore_views_info
3391 3401
$_$;
3392 3402

  
3393 3403

  

Also available in: Unified diff