-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdescribe_resultset--1.0.0.sql
More file actions
40 lines (36 loc) · 933 Bytes
/
describe_resultset--1.0.0.sql
File metadata and controls
40 lines (36 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* describe_resultset--1.0.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION describe_resultset" to load this file. \quit
CREATE TYPE describe_resultset_data AS
(
column_name name,
column_type oid,
column_len INT,
column_attrs TEXT
);
CREATE FUNCTION describe_resultset_internal(cmd TEXT)
RETURNS SETOF describe_resultset_data
AS 'MODULE_PATHNAME','describe_resultset'
LANGUAGE C STABLE STRICT;
CREATE FUNCTION describe_resultset(cmd TEXT)
RETURNS TABLE (
column_name name,
column_type oid,
column_type_name name,
column_len INT,
column_attrs TEXT
)
LANGUAGE SQL STABLE STRICT
AS $$
SELECT
f.column_name
,f.column_type
,pgt.typname
,f.column_len
,f.column_attrs
FROM
describe_resultset_internal(cmd) f
INNER JOIN
pg_type pgt
ON pgt.oid = f.column_type;
$$;