Revision 12652
Added by Aaron Marcuse-Kubitza almost 11 years ago
util.sql | ||
---|---|---|
3520 | 3520 |
|
3521 | 3521 |
|
3522 | 3522 |
-- |
3523 |
-- Name: to_freq(regclass); Type: FUNCTION; Schema: util; Owner: - |
|
3524 |
-- |
|
3525 |
|
|
3526 |
CREATE FUNCTION to_freq(table_ regclass) RETURNS void |
|
3527 |
LANGUAGE sql |
|
3528 |
AS $_$ |
|
3529 |
-- save data before truncating main table |
|
3530 |
SELECT util.copy_types_and_data($1, 'pg_temp.__copy'); |
|
3531 |
|
|
3532 |
-- repopulate main table w/ copies column |
|
3533 |
SELECT util.truncate($1); |
|
3534 |
SELECT util.eval($$ALTER TABLE $$||$1||$$ ADD COLUMN copies bigint NOT NULL$$); |
|
3535 |
SELECT util.populate_table($1, $$ |
|
3536 |
SELECT (table_).*, copies |
|
3537 |
FROM ( |
|
3538 |
SELECT table_, COUNT(*) AS copies |
|
3539 |
FROM pg_temp.__copy table_ |
|
3540 |
GROUP BY table_ |
|
3541 |
) s |
|
3542 |
$$); |
|
3543 |
|
|
3544 |
-- delete temp table so it doesn't stay around until end of connection |
|
3545 |
SELECT util.drop_table('pg_temp.__copy'); |
|
3546 |
$_$; |
|
3547 |
|
|
3548 |
|
|
3549 |
-- |
|
3523 | 3550 |
-- Name: to_global_col_names(regclass); Type: FUNCTION; Schema: util; Owner: - |
3524 | 3551 |
-- |
3525 | 3552 |
|
Also available in: Unified diff
schemas/util.sql: added to_freq(regclass)