forked from python-postgres/be
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtupledesc.sql
More file actions
36 lines (30 loc) · 726 Bytes
/
Copy pathtupledesc.sql
File metadata and controls
36 lines (30 loc) · 726 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
DROP TABLE IF EXISTS tupdtest;
CREATE TABLE tupdtest (i int, t text, c circle);
CREATE OR REPLACE FUNCTION describe_tupd(table_name text) RETURNS text
LANGUAGE python AS
$python$
from Postgres.types import regtype
from Postgres import Type
formatting = """
column_names: %s
column_types: %s
pg_column_types: %s
column_count: %d
len(): %d
"""
@pytypes
def main(table_name):
td = Type(regtype(table_name)).descriptor
return formatting %(
td.column_names,
td.column_types,
td.pg_column_types,
td.column_count,
len(td),
)
$python$;
SELECT describe_tupd('tupdtest');
ALTER TABLE tupdtest DROP COLUMN t;
SELECT describe_tupd('tupdtest');
ALTER TABLE tupdtest ADD COLUMN t2 text;
SELECT describe_tupd('tupdtest');