Created
July 30, 2014 15:26
-
-
Save matheusoliveira/e588f2a2b4803ab216be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DO $$ | |
DECLARE | |
v_schema text; | |
v_table text; | |
v_column text; | |
v_look_for text := 'foo'; | |
v_ret bool; | |
BEGIN | |
FOR v_schema, v_table IN | |
SELECT table_schema, table_name | |
FROM information_schema.tables | |
WHERE table_type = 'BASE TABLE' | |
AND table_schema !~ '^(pg_.*|information_schema)$' | |
LOOP | |
FOR v_column IN | |
SELECT column_name | |
FROM information_schema.columns | |
WHERE table_schema = v_schema | |
AND table_name = v_table | |
LOOP | |
EXECUTE format('SELECT EXISTS(SELECT 1 FROM %I.%I WHERE %I::text LIKE %L)', v_schema, v_table, v_column, v_look_for) INTO v_ret; | |
IF (v_ret) THEN | |
RAISE NOTICE '%.%.%', v_schema, v_table, v_column; | |
END IF; | |
END LOOP; | |
END LOOP; | |
END; | |
$$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment