-
Notifications
You must be signed in to change notification settings - Fork 37
Open
Description
INTERVAL type is officially released.
https://cloud.google.com/spanner/docs/reference/standard-sql/lexical#interval_literals
https://cloud.google.com/spanner/docs/reference/standard-sql/data-types#interval_type
Current Behavior
spanner> SELECT INTERVAL 1 DAY AS `interval`;
+--------------------+
| interval |
| UNKNOWN |
+--------------------+
| string_value:"P1D" |
+--------------------+
1 rows in set (3.28 msecs)
Format
I recommend to use ISO 8601 duration format because:
It is used as internal representation of INTERVAL.
// Encoded as `string`, in `ISO8601` duration format -
// `P[n]Y[n]M[n]DT[n]H[n]M[n[.fraction]]S`
// where `n` is an integer.
// For example, `P1Y2M3DT4H5M6.5S` represents time duration of 1 year, 2
// months, 3 days, 4 hours, 5 minutes, and 6.5 seconds.
INTERVAL = 16;
Spanner Studio and gcloud spanner databases execute-sql uses the same format.
Implementation
$ gcloud spanner databases execute-sql ${SPANNER_DATABASE_ID} --sql 'SELECT INTERVAL 1 DAY AS `interval`'
interval
P1D
I think it is good enough to use Interval.String() and NullInterval.String() because it format value as ISO 8601 duration.
https://pkg.go.dev/cloud.google.com/go/spanner#Interval.String
String returns the ISO8601 duration format string representation of the interval.
Metadata
Metadata
Assignees
Labels
No labels