Created
October 9, 2015 19:51
-
-
Save qdw/00d9be4ce103377fe03c to your computer and use it in GitHub Desktop.
This convenience function lets you query stats by table and column name (as opposed to using numeric IDs) (PostgreSQL, PL/pgSQL)
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
CREATE OR REPLACE FUNCTION stats(my_table text, my_column text) RETURNS SETOF pg_statistic AS $$ | |
DECLARE | |
my_relid oid := (SELECT oid FROM pg_class WHERE relname = my_table); | |
my_attnum smallint := (SELECT attnum FROM pg_attribute WHERE attrelid = my_relid AND attname = my_column); | |
BEGIN | |
RETURN QUERY SELECT * FROM pg_statistic WHERE starelid = my_relid AND staattnum = my_attnum; | |
END; | |
$$ LANGUAGE plpgsql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment