-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
datatypes.go
60 lines (55 loc) · 1.32 KB
/
datatypes.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
package postgresql
import (
"time"
)
// Constants for naming PostgreSQL data types both in
// their short and long versions.
const (
PgBool = "boolean"
PgSmallInt = "smallint"
PgInteger = "integer"
PgBigInt = "bigint"
PgReal = "real"
PgDoublePrecision = "double precision"
PgNumeric = "numeric"
PgText = "text"
PgTimestampWithTimeZone = "timestamp with time zone"
PgTimestampWithoutTimeZone = "timestamp without time zone"
PgSerial = "serial"
PgJSONb = "jsonb"
)
// Types from pguint
const (
PgUint8 = "uint8"
)
// DerivePgDatatype returns the appropriate PostgreSQL data type
// that could hold the value.
func (p *Postgresql) derivePgDatatype(value interface{}) string {
if p.Uint64Type == PgUint8 {
if _, ok := value.(uint64); ok {
return PgUint8
}
}
switch value.(type) {
case bool:
return PgBool
case uint64:
return PgNumeric
case int64, int, uint, uint32:
return PgBigInt
case int32:
return PgInteger
case int16, int8:
return PgSmallInt
case float64:
return PgDoublePrecision
case float32:
return PgReal
case string:
return PgText
case time.Time:
return PgTimestampWithoutTimeZone
default:
return PgText
}
}