11package postgres
22
33import (
4+ _ "embed"
45 "fmt"
56 "strings"
67 "time"
@@ -11,6 +12,12 @@ import (
1112 "github.com/hymkor/sqlbless/internal/misc"
1213)
1314
15+ //go:embed tables.sql
16+ var tablesSql string
17+
18+ //go:embed columns.sql
19+ var columnsSql string
20+
1421var postgresTypeNameToFormat = map [string ][2 ]string {
1522 "TIMESTAMPTZ" : [2 ]string {"TIMESTAMP WITH TIME ZONE" , dialect .DateTimeTzLayout },
1623 "TIMESTAMP" : [2 ]string {"TIMESTAMP" , dialect .DateTimeLayout },
@@ -44,55 +51,9 @@ func (ph *placeHolder) Values() (result []any) {
4451}
4552
4653var postgresSpec = & dialect.Entry {
47- Usage : "sqlbless postgres://<USERNAME>:<PASSWORD>@<HOSTNAME>:<PORT>/<DBNAME>?sslmode=disable" ,
48- SQLForColumns : `
49- with target as (
50- select to_regclass($1)::oid as oid
51- )
52- select
53- a.attname as "NAME",
54- case a.attnotnull
55- when true then 'NOT NULL'
56- else 'NULL'
57- end as "NULL?",
58- format_type(a.atttypid, a.atttypmod) as "TYPE"
59- from target t
60- join pg_attribute a
61- on a.attrelid = t.oid
62- where a.attnum > 0
63- and not a.attisdropped
64- order by a.attnum` ,
65- SQLForTables : `
66- select
67- n.nspname || '.' || c.relname as full_name,
68- n.nspname as table_schema,
69- c.relname as table_name,
70- case c.relkind
71- when 'r' then 'BASE TABLE'
72- when 'p' then 'PARTITIONED TABLE'
73- when 'v' then 'VIEW'
74- when 'm' then 'MATERIALIZED VIEW'
75- when 'f' then 'FOREIGN TABLE'
76- end as table_type,
77- c.reltuples::bigint as estimated_rows,
78- obj_description(c.oid,'pg_class') as remarks
79- from pg_class c
80- join pg_namespace n
81- on n.oid = c.relnamespace
82- where c.relkind in ('r','p','v','m','f')
83- order by
84- case n.nspname
85- when 'pg_catalog' then 9
86- when 'information_schema' then 8
87- else 0
88- end,
89- case c.relkind
90- when 'r' then 0
91- when 'p' then 1
92- else 9
93- end,
94- n.nspname,
95- c.relname` ,
54+ Usage : "sqlbless postgres://<USERNAME>:<PASSWORD>@<HOSTNAME>:<PORT>/<DBNAME>?sslmode=disable" ,
55+ SQLForColumns : columnsSql ,
56+ SQLForTables : tablesSql ,
9657 TypeConverterFor : postgresTypeNameToConv ,
9758 PlaceHolder : & placeHolder {},
9859 TableNameField : "full_name" ,
0 commit comments