forked from decred/dcrdata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
64 lines (58 loc) · 1.22 KB
/
common.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
52
53
54
55
56
57
58
59
60
61
62
63
64
package internal
import "fmt"
const (
IndexExists = `SELECT 1
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.relname = $1 AND n.nspname = $2;`
IndexIsUnique = `SELECT indisunique
FROM pg_index i
JOIN pg_class c ON c.oid = i.indexrelid
JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.relname = $1 AND n.nspname = $2`
)
func makeARRAYOfTEXT(text []string) string {
if len(text) == 0 {
return "ARRAY['']"
}
sTEXTARRAY := "ARRAY["
for i, txt := range text {
if i == len(text)-1 {
sTEXTARRAY += fmt.Sprintf(`'%s'`, txt)
break
}
sTEXTARRAY += fmt.Sprintf(`'%s', `, txt)
}
sTEXTARRAY += "]"
return sTEXTARRAY
}
func makeARRAYOfUnquotedTEXT(text []string) string {
if len(text) == 0 {
return "ARRAY[]"
}
sTEXTARRAY := "ARRAY["
for i, txt := range text {
if i == len(text)-1 {
sTEXTARRAY += txt
break
}
sTEXTARRAY += fmt.Sprintf(`%s, `, txt)
}
sTEXTARRAY += "]"
return sTEXTARRAY
}
func makeARRAYOfBIGINTs(ints []uint64) string {
if len(ints) == 0 {
return "ARRAY[]::BIGINT[]"
}
ARRAY := "ARRAY["
for i, v := range ints {
if i == len(ints)-1 {
ARRAY += fmt.Sprintf(`%d`, v)
break
}
ARRAY += fmt.Sprintf(`%d, `, v)
}
ARRAY += "]"
return ARRAY
}