-
Notifications
You must be signed in to change notification settings - Fork 4
/
query.go
51 lines (49 loc) · 1 KB
/
query.go
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
41
42
43
44
45
46
47
48
49
50
51
package exceltesting
const (
getPrimaryKeyQuery = `
SELECT
array_to_string(ARRAY_AGG(A.attname), ',') AS column_names
FROM
pg_class AS T
, pg_class AS i
, pg_index AS ix
, pg_attribute AS A
, pg_tables AS ta
WHERE
T.oid = ix.indrelid
AND i.oid = ix.indexrelid
AND ix.indisprimary = TRUE
AND A.attrelid = T.oid
AND A.attnum = ANY(ix.indkey)
AND T.relkind IN ('r', 'p') -- TODO: 将来的には他の relkind にも対応する予定
AND T.relname = ta.tablename
AND ta.schemaname = CURRENT_SCHEMA()
AND T.relname = $1
GROUP BY
T.relname
, i.relname
, ix.indisprimary
ORDER BY
T.relname
, i.relname
;`
getTableNotNullColumns = `
SELECT
column_name
, udt_name
FROM
information_schema.columns
WHERE
table_schema = CURRENT_SCHEMA()
AND table_name = $1
AND is_nullable = 'NO'
/*
If column_default exists, no explicit value needs to be specified.
For example, the automatic incremental types such as serial, bigserial, etc. are applicable.
*/
AND column_default IS NULL
ORDER BY
ordinal_position
;
`
)