@@ -56,17 +56,25 @@ var (
56
56
// Datum represents a SQL value.
57
57
type Datum interface {
58
58
TypedExpr
59
+
60
+ // AmbiguousFormat indicates whether the result of formatting this Datum can
61
+ // be interpreted into more than one type. Used with
62
+ // fmtFlags.disambiguateDatumTypes.
63
+ AmbiguousFormat () bool
64
+
59
65
// Compare returns -1 if the receiver is less than other, 0 if receiver is
60
66
// equal to other and +1 if receiver is greater than other.
61
67
// TODO(nvanbenschoten) Should we look into merging this with cmpOps?
62
68
Compare (other Datum ) int
69
+
63
70
// Prev returns the previous datum and true, if one exists, or nil
64
71
// and false. The previous datum satisfied the following
65
72
// definition: if the receiver is "b" and the returned datum is "a",
66
73
// then "a < b" and no other datum will compare such that "a < c <
67
74
// b".
68
75
// The return value is undefined if `IsMin()` returns true.
69
76
Prev () (Datum , bool )
77
+
70
78
// IsMin returns true if the datum is equal to the minimum value the datum
71
79
// type can hold.
72
80
IsMin () bool
@@ -78,6 +86,7 @@ type Datum interface {
78
86
// b".
79
87
// The return value is undefined if `IsMax()` returns true.
80
88
Next () (Datum , bool )
89
+
81
90
// IsMax returns true if the datum is equal to the maximum value the datum
82
91
// type can hold.
83
92
IsMax () bool
@@ -202,6 +211,9 @@ func (d *DBool) max() (Datum, bool) {
202
211
return DBoolTrue , true
203
212
}
204
213
214
+ // AmbiguousFormat implements the Datum interface.
215
+ func (* DBool ) AmbiguousFormat () bool { return false }
216
+
205
217
// Format implements the NodeFormatter interface.
206
218
func (d * DBool ) Format (buf * bytes.Buffer , f FmtFlags ) {
207
219
buf .WriteString (strconv .FormatBool (bool (* d )))
@@ -291,6 +303,9 @@ func (d *DInt) min() (Datum, bool) {
291
303
return dMinInt , true
292
304
}
293
305
306
+ // AmbiguousFormat implements the Datum interface.
307
+ func (* DInt ) AmbiguousFormat () bool { return true }
308
+
294
309
// Format implements the NodeFormatter interface.
295
310
func (d * DInt ) Format (buf * bytes.Buffer , f FmtFlags ) {
296
311
buf .WriteString (strconv .FormatInt (int64 (* d ), 10 ))
@@ -391,6 +406,9 @@ func (d *DFloat) min() (Datum, bool) {
391
406
return dMinFloat , true
392
407
}
393
408
409
+ // AmbiguousFormat implements the Datum interface.
410
+ func (* DFloat ) AmbiguousFormat () bool { return true }
411
+
394
412
// Format implements the NodeFormatter interface.
395
413
func (d * DFloat ) Format (buf * bytes.Buffer , f FmtFlags ) {
396
414
fl := float64 (* d )
@@ -474,6 +492,9 @@ func (d *DDecimal) min() (Datum, bool) {
474
492
return nil , false
475
493
}
476
494
495
+ // AmbiguousFormat implements the Datum interface.
496
+ func (* DDecimal ) AmbiguousFormat () bool { return true }
497
+
477
498
// Format implements the NodeFormatter interface.
478
499
func (d * DDecimal ) Format (buf * bytes.Buffer , f FmtFlags ) {
479
500
buf .WriteString (d .Dec .String ())
@@ -551,6 +572,9 @@ func (d *DString) max() (Datum, bool) {
551
572
return nil , false
552
573
}
553
574
575
+ // AmbiguousFormat implements the Datum interface.
576
+ func (* DString ) AmbiguousFormat () bool { return true }
577
+
554
578
// Format implements the NodeFormatter interface.
555
579
func (d * DString ) Format (buf * bytes.Buffer , f FmtFlags ) {
556
580
encodeSQLStringWithFlags (buf , string (* d ), f )
@@ -607,6 +631,9 @@ func NewDCollatedString(contents string, locale string, env *CollationEnvironmen
607
631
return & d
608
632
}
609
633
634
+ // AmbiguousFormat implements the Datum interface.
635
+ func (* DCollatedString ) AmbiguousFormat () bool { return false }
636
+
610
637
// Format implements the NodeFormatter interface.
611
638
func (d * DCollatedString ) Format (buf * bytes.Buffer , f FmtFlags ) {
612
639
encodeSQLString (buf , d .Contents )
@@ -731,6 +758,9 @@ func (d *DBytes) max() (Datum, bool) {
731
758
return nil , false
732
759
}
733
760
761
+ // AmbiguousFormat implements the Datum interface.
762
+ func (* DBytes ) AmbiguousFormat () bool { return false }
763
+
734
764
// Format implements the NodeFormatter interface.
735
765
func (d * DBytes ) Format (buf * bytes.Buffer , f FmtFlags ) {
736
766
encodeSQLBytes (buf , string (* d ))
@@ -848,6 +878,9 @@ func (d *DDate) min() (Datum, bool) {
848
878
return nil , false
849
879
}
850
880
881
+ // AmbiguousFormat implements the Datum interface.
882
+ func (* DDate ) AmbiguousFormat () bool { return true }
883
+
851
884
// Format implements the NodeFormatter interface.
852
885
func (d * DDate ) Format (buf * bytes.Buffer , f FmtFlags ) {
853
886
if ! f .bareStrings {
@@ -1003,6 +1036,9 @@ func (d *DTimestamp) max() (Datum, bool) {
1003
1036
return nil , false
1004
1037
}
1005
1038
1039
+ // AmbiguousFormat implements the Datum interface.
1040
+ func (* DTimestamp ) AmbiguousFormat () bool { return true }
1041
+
1006
1042
// Format implements the NodeFormatter interface.
1007
1043
func (d * DTimestamp ) Format (buf * bytes.Buffer , f FmtFlags ) {
1008
1044
if ! f .bareStrings {
@@ -1107,6 +1143,9 @@ func (d *DTimestampTZ) max() (Datum, bool) {
1107
1143
return nil , false
1108
1144
}
1109
1145
1146
+ // AmbiguousFormat implements the Datum interface.
1147
+ func (* DTimestampTZ ) AmbiguousFormat () bool { return true }
1148
+
1110
1149
// Format implements the NodeFormatter interface.
1111
1150
func (d * DTimestampTZ ) Format (buf * bytes.Buffer , f FmtFlags ) {
1112
1151
if ! f .bareStrings {
@@ -1321,11 +1360,18 @@ func (d *DInterval) ValueAsString() string {
1321
1360
return (time .Duration (d .Duration .Nanos ) * time .Nanosecond ).String ()
1322
1361
}
1323
1362
1324
- // Format implements the NodeFormatter interface. Example: "INTERVAL `1h2m`".
1363
+ // AmbiguousFormat implements the Datum interface.
1364
+ func (* DInterval ) AmbiguousFormat () bool { return true }
1365
+
1366
+ // Format implements the NodeFormatter interface.
1325
1367
func (d * DInterval ) Format (buf * bytes.Buffer , f FmtFlags ) {
1326
- buf .WriteString ("INTERVAL '" )
1368
+ if ! f .bareStrings {
1369
+ buf .WriteByte ('\'' )
1370
+ }
1327
1371
buf .WriteString (d .ValueAsString ())
1328
- buf .WriteByte ('\'' )
1372
+ if ! f .bareStrings {
1373
+ buf .WriteByte ('\'' )
1374
+ }
1329
1375
}
1330
1376
1331
1377
// Size implements the Datum interface.
@@ -1482,6 +1528,9 @@ func (d *DTuple) IsMin() bool {
1482
1528
return true
1483
1529
}
1484
1530
1531
+ // AmbiguousFormat implements the Datum interface.
1532
+ func (* DTuple ) AmbiguousFormat () bool { return false }
1533
+
1485
1534
// Format implements the NodeFormatter interface.
1486
1535
func (d * DTuple ) Format (buf * bytes.Buffer , f FmtFlags ) {
1487
1536
buf .WriteByte ('(' )
@@ -1602,6 +1651,9 @@ func (dNull) min() (Datum, bool) {
1602
1651
return DNull , true
1603
1652
}
1604
1653
1654
+ // AmbiguousFormat implements the Datum interface.
1655
+ func (dNull ) AmbiguousFormat () bool { return false }
1656
+
1605
1657
// Format implements the NodeFormatter interface.
1606
1658
func (dNull ) Format (buf * bytes.Buffer , f FmtFlags ) {
1607
1659
buf .WriteString ("NULL" )
@@ -1691,6 +1743,9 @@ func (d *DArray) IsMin() bool {
1691
1743
return d .Len () == 0
1692
1744
}
1693
1745
1746
+ // AmbiguousFormat implements the Datum interface.
1747
+ func (* DArray ) AmbiguousFormat () bool { return false }
1748
+
1694
1749
// Format implements the NodeFormatter interface.
1695
1750
func (d * DArray ) Format (buf * bytes.Buffer , f FmtFlags ) {
1696
1751
buf .WriteByte ('{' )
@@ -1760,6 +1815,9 @@ type DTable struct {
1760
1815
ValueGenerator
1761
1816
}
1762
1817
1818
+ // AmbiguousFormat implements the Datum interface.
1819
+ func (* DTable ) AmbiguousFormat () bool { return false }
1820
+
1763
1821
// Format implements the NodeFormatter interface.
1764
1822
func (t * DTable ) Format (buf * bytes.Buffer , _ FmtFlags ) {
1765
1823
buf .WriteString ("<generated>" )
0 commit comments