@@ -35,6 +35,40 @@ CREATE TABLE pgdoc.selected_docs (
35
35
-- INSERT INTO pgdoc.selected_docs SELECT 'a', * FROM doc_UDF_show_simplelines_asXHTML('public','','^(ST_|_st_|geometry_)') WHERE j->>'language'!='c';
36
36
37
37
38
+ -- -- -- -- -- --
39
+ -- Generic functions:
40
+ CREATE FUNCTION pgdoc .rel_description(
41
+ p_relname text ,
42
+ p_schemaname text DEFAULT NULL
43
+ ) RETURNS text AS $f$
44
+ -- see https://stackoverflow.com/a/12736192/287948
45
+ SELECT obj_description((CASE
46
+ WHEN strpos($1 , ' .' )> 0 THEN $1
47
+ WHEN $2 IS NULL THEN ' public.' || $1
48
+ ELSE $2 || ' .' || $1
49
+ END)::regclass, ' pg_class' );
50
+ $f$ LANGUAGE SQL;
51
+
52
+ CREATE FUNCTION pgdoc .col_description(
53
+ p_relname text , -- table name or schema.table
54
+ p_colname text , -- table's column name
55
+ p_database text DEFAULT NULL -- NULL for current
56
+ ) RETURNS text AS $f$
57
+ -- see https://stackoverflow.com/a/12736192/287948
58
+ WITH r AS (
59
+ SELECT CASE WHEN array_length(x,1 )= 1 THEN array[' public' ,x[1 ]] ELSE x END
60
+ FROM regexp_split_to_array(p_relname,' \. ' ) t(x)
61
+ )
62
+ SELECT col_description(p_relname::regClass, ordinal_position)
63
+ FROM r, information_schema .columns i
64
+ WHERE i .table_catalog = CASE WHEN $3 IS NULL THEN current_database() ELSE $3 END
65
+ AND i .table_schema = r .x [1 ]
66
+ AND i .table_name = r .x [2 ]
67
+ AND i .column_name = p_colname
68
+ $f$ LANGUAGE SQL;
69
+ -- SELECT col_description('tableName','colName');
70
+ -- SELECT col_description('schemaName.tableName','colName','databaseName);
71
+
38
72
-- -- -- -- -- --
39
73
-- -- Functions
40
74
0 commit comments