Revision 12732
Added by Aaron Marcuse-Kubitza almost 11 years ago
util.sql | ||
---|---|---|
3448 | 3448 |
LANGUAGE plpgsql STRICT |
3449 | 3449 |
AS $_$ |
3450 | 3450 |
DECLARE |
3451 |
sql text = $$ALTER TABLE $$||table_||$$
|
|
3452 |
$$||NULLIF(array_to_string(ARRAY(
|
|
3453 |
SELECT
|
|
3454 |
$$ALTER COLUMN $$||col_name_sql||$$ TYPE $$||target_type
|
|
3455 |
||$$ USING $$||col_name_sql||$$::$$||target_type
|
|
3456 |
FROM
|
|
3457 |
(
|
|
3458 |
SELECT
|
|
3459 |
quote_ident(col_name) AS col_name_sql
|
|
3460 |
, util.col_type((table_, col_name)) AS curr_type
|
|
3461 |
, type AS target_type
|
|
3462 |
FROM unnest(col_casts)
|
|
3463 |
) s
|
|
3464 |
WHERE curr_type != target_type
|
|
3465 |
), '
|
|
3466 |
, '), '');
|
|
3451 |
sql text = $$ALTER TABLE $$||table_||$$
|
|
3452 |
$$||( |
|
3453 |
SELECT
|
|
3454 |
string_agg($$ALTER COLUMN $$||col_name_sql||$$ TYPE $$||target_type
|
|
3455 |
||$$ USING $$||col_name_sql||$$::$$||target_type, $$
|
|
3456 |
, $$)
|
|
3457 |
FROM
|
|
3458 |
(
|
|
3459 |
SELECT
|
|
3460 |
quote_ident(col_name) AS col_name_sql
|
|
3461 |
, util.col_type((table_, col_name)) AS curr_type
|
|
3462 |
, type AS target_type
|
|
3463 |
FROM unnest(col_casts)
|
|
3464 |
) s
|
|
3465 |
WHERE curr_type != target_type
|
|
3466 |
); |
|
3467 | 3467 |
BEGIN |
3468 |
PERFORM util.debug_print_sql(sql);
|
|
3469 |
EXECUTE COALESCE(sql, '');
|
|
3468 |
PERFORM util.debug_print_sql(sql);
|
|
3469 |
EXECUTE COALESCE(sql, '');
|
|
3470 | 3470 |
END; |
3471 | 3471 |
$_$; |
3472 | 3472 |
|
Also available in: Unified diff
schemas/util.sql: set_col_types(): use string_agg() instead of array_to_string(ARRAY) for clarity