Project

General

Profile

« Previous | Next » 

Revision 12733

schemas/util.sql: set_col_types(): use simpler util.eval() instead of manual EXECUTE/util.debug_print_sql()

View differences:

trunk/schemas/util.sql
3445 3445
--
3446 3446

  
3447 3447
CREATE FUNCTION set_col_types(table_ regclass, col_casts col_cast[]) RETURNS void
3448
    LANGUAGE plpgsql STRICT
3448
    LANGUAGE sql
3449 3449
    AS $_$
3450
DECLARE
3451
	sql text = $$ALTER TABLE $$||table_||$$
3450
SELECT util.eval($$ALTER TABLE $$||$1||$$
3452 3451
$$||(
3453 3452
	SELECT
3454 3453
	string_agg($$ALTER COLUMN $$||col_name_sql||$$ TYPE $$||target_type
......
3458 3457
	(
3459 3458
		SELECT
3460 3459
		  quote_ident(col_name) AS col_name_sql
3461
		, util.col_type((table_, col_name)) AS curr_type
3460
		, util.col_type(($1, col_name)) AS curr_type
3462 3461
		, type AS target_type
3463
		FROM unnest(col_casts)
3462
		FROM unnest($2)
3464 3463
	) s
3465 3464
	WHERE curr_type != target_type
3466
);
3467
BEGIN
3468
	PERFORM util.debug_print_sql(sql);
3469
	EXECUTE COALESCE(sql, '');
3470
END;
3465
))
3471 3466
$_$;
3472 3467

  
3473 3468

  

Also available in: Unified diff