diff options
Diffstat (limited to 'util/postgres.go')
| -rw-r--r-- | util/postgres.go | 31 | 
1 files changed, 31 insertions, 0 deletions
| diff --git a/util/postgres.go b/util/postgres.go new file mode 100644 index 0000000..a108446 --- /dev/null +++ b/util/postgres.go | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | package util | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "regexp" | ||
| 5 | "strings" | ||
| 6 | ) | ||
| 7 | |||
| 8 | var ( | ||
| 9 | pgArrayReg = regexp.MustCompile(`(((?P<value>(([^",\\{}\s(NULL)])+|"([^"\\]|\\"|\\\\)*")))(,)?)`) | ||
| 10 | pgValueIdx int | ||
| 11 | ) | ||
| 12 | |||
| 13 | func init() { | ||
| 14 | for i, subexp := range pgArrayReg.SubexpNames() { | ||
| 15 | if subexp == "value" { | ||
| 16 | pgValueIdx = i | ||
| 17 | break | ||
| 18 | } | ||
| 19 | } | ||
| 20 | } | ||
| 21 | |||
| 22 | func PGArray(array []byte) []string { | ||
| 23 | var results []string | ||
| 24 | matches := pgArrayReg.FindAllStringSubmatch(string(array), -1) | ||
| 25 | for _, match := range matches { | ||
| 26 | s := match[pgValueIdx] | ||
| 27 | s = strings.Trim(s, "\"") | ||
| 28 | results = append(results, s) | ||
| 29 | } | ||
| 30 | return results | ||
| 31 | } | ||
