Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tree: cast TIMESTAMP to TEXT without timezone data #51692

Merged
merged 1 commit into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/ccl/backupccl/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestShowBackup(t *testing.T) {

const full, inc, inc2 = LocalFoo + "/full", LocalFoo + "/inc", LocalFoo + "/inc2"

beforeTS := sqlDB.QueryStr(t, `SELECT now()::string`)[0][0]
beforeTS := sqlDB.QueryStr(t, `SELECT now()::timestamp::string`)[0][0]
sqlDB.Exec(t, fmt.Sprintf(`BACKUP DATABASE data TO $1 AS OF SYSTEM TIME '%s'`, beforeTS), full)

res := sqlDB.QueryStr(t, `SELECT table_name, start_time::string, end_time::string, rows, is_full_cluster FROM [SHOW BACKUP $1]`, full)
Expand All @@ -51,7 +51,7 @@ func TestShowBackup(t *testing.T) {

// Backup the changes by appending to the base and by making a separate
// inc backup.
incTS := sqlDB.QueryStr(t, `SELECT now()::string`)[0][0]
incTS := sqlDB.QueryStr(t, `SELECT now()::timestamp::string`)[0][0]
sqlDB.Exec(t, fmt.Sprintf(`BACKUP DATABASE data TO $1 AS OF SYSTEM TIME '%s'`, incTS), full)
sqlDB.Exec(t, fmt.Sprintf(`BACKUP DATABASE data TO $1 AS OF SYSTEM TIME '%s' INCREMENTAL FROM $2`, incTS), inc, full)

Expand All @@ -75,7 +75,7 @@ func TestShowBackup(t *testing.T) {

// Backup the changes again, by appending to the base and by making a
// separate inc backup.
inc2TS := sqlDB.QueryStr(t, `SELECT now()::string`)[0][0]
inc2TS := sqlDB.QueryStr(t, `SELECT now()::timestamp::string`)[0][0]
sqlDB.Exec(t, fmt.Sprintf(`BACKUP DATABASE data TO $1 AS OF SYSTEM TIME '%s'`, inc2TS), full)
sqlDB.Exec(t, fmt.Sprintf(`BACKUP DATABASE data TO $1 AS OF SYSTEM TIME '%s' INCREMENTAL FROM $2, $3`, inc2TS), inc2, full, inc)

Expand Down
4 changes: 3 additions & 1 deletion pkg/cli/sql_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,9 @@ func formatVal(val driver.Value, showPrintableUnicode bool, showNewLinesAndTabs
lex.BytesEncodeEscape, false /* skipHexPrefix */)

case time.Time:
return t.Format(tree.TimestampOutputFormat)
// Since we do not know whether the datum is Timestamp or TimestampTZ,
// output the full format.
return t.Format(tree.TimestampTZOutputFormat)
}

return fmt.Sprint(val)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/testdata/dump/row
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ CREATE TABLE t (
);

INSERT INTO t (i, f, s, b, d, t, ts, n, o, e, u, ip, j, ary, tz, e1, e2, s1, s2, oi) VALUES
(1, 2.3, 'striiing', '\x613162326333', '2016-03-26', '01:02:03.456', '2016-01-25 10:10:10+00:00', '02:30:30', true, 1.2345, 'e9716c74-2638-443d-90ed-ffde7bea7d1d', '192.168.0.1', '{"a": "b"}', ARRAY['hello','world'], '2016-01-25 10:10:10+00:00', 3, 4.5, 's', 'hello' COLLATE en_u_ks_level2, 6),
(1, 2.3, 'striiing', '\x613162326333', '2016-03-26', '01:02:03.456', '2016-01-25 10:10:10', '02:30:30', true, 1.2345, 'e9716c74-2638-443d-90ed-ffde7bea7d1d', '192.168.0.1', '{"a": "b"}', ARRAY['hello','world'], '2016-01-25 10:10:10+00:00', 3, 4.5, 's', 'hello' COLLATE en_u_ks_level2, 6),
(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
(NULL, '+Inf', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'Infinity', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
(NULL, '-Inf', NULL, NULL, NULL, NULL, NULL, NULL, NULL, '-Infinity', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
Expand Down
2 changes: 1 addition & 1 deletion pkg/internal/sqlsmith/bulkio.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func makeAsOf(s *Smither) tree.AsOfClause {
case 1:
expr = tree.NewStrVal("-2s")
case 2:
expr = tree.NewStrVal(timeutil.Now().Add(-2 * time.Second).Format(tree.TimestampOutputFormat))
expr = tree.NewStrVal(timeutil.Now().Add(-2 * time.Second).Format(tree.TimestampTZOutputFormat))
case 3:
expr = sqlbase.RandDatum(s.rnd, types.Interval, false /* nullOk */)
case 4:
Expand Down
4 changes: 3 additions & 1 deletion pkg/sql/copy_in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,10 @@ func TestCopyRandom(t *testing.T) {
dt = tree.MakeDTime(timeofday.FromTimeAllow2400(d))
} else if typs[i].Family() == types.TimeTZFamily {
dt = tree.NewDTimeTZ(timetz.MakeTimeTZFromTimeAllow2400(d))
} else {
} else if typs[i].Family() == types.TimestampFamily {
dt = tree.MustMakeDTimestamp(d, time.Microsecond)
} else {
dt = tree.MustMakeDTimestampTZ(d, time.Microsecond)
}
ds = tree.AsStringWithFlags(dt, tree.FmtBareStrings)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/builtin_function
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ SELECT
quote_literal('2018-06-11 12:13:14'::timestamp), quote_nullable('2018-06-11 12:13:14'::timestamp),
quote_literal('2018-06-11'::date), quote_nullable('2018-06-11'::date)
----
'1 day' '1 day' '2018-06-11 12:13:14+00:00' '2018-06-11 12:13:14+00:00' '2018-06-11' '2018-06-11'
'1 day' '1 day' '2018-06-11 12:13:14' '2018-06-11 12:13:14' '2018-06-11' '2018-06-11'

query TTBB
SELECT
Expand Down
82 changes: 41 additions & 41 deletions pkg/sql/logictest/testdata/logic_test/datetime
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ SELECT * FROM t WHERE a = '2015-08-25 04:45:45.53453+01:00'::timestamp
2015-08-25 04:45:45.53453 +0000 +0000 2015-08-25 00:00:00 +0000 +0000 02:45:02.234

# insert duplicate value with different time zone offset
statement error duplicate key value \(a\)=\('2015-08-30 03:34:45\.34567\+00:00'\) violates unique constraint "primary"
statement error duplicate key value \(a\)=\('2015-08-30 03:34:45\.34567'\) violates unique constraint "primary"
INSERT INTO t VALUES
('2015-08-30 03:34:45.34567-07:00', '2015-08-31', '35h2s')

Expand Down Expand Up @@ -637,45 +637,45 @@ query ITTBT
SELECT k, element, input, date_trunc(element, input::timestamp) = date_trunc_result, date_trunc(element, input::timestamp)::string
FROM ex WHERE date_trunc_result IS NOT NULL ORDER BY k
----
1 year 2001-04-10 12:04:59 +0000 UTC true 2001-01-01 00:00:00+00:00
2 year 2016-02-10 19:46:33.306158 +0000 UTC true 2016-01-01 00:00:00+00:00
3 years 2016-02-10 19:46:33.306158 +0000 UTC true 2016-01-01 00:00:00+00:00
4 quarter 2001-04-10 12:04:59 +0000 UTC true 2001-04-01 00:00:00+00:00
5 quarter 2016-02-10 19:46:33.306158 +0000 UTC true 2016-01-01 00:00:00+00:00
6 quarter 2016-05-10 19:46:33.306158 +0000 UTC true 2016-04-01 00:00:00+00:00
7 quarter 2016-09-09 19:46:33.306158 +0000 UTC true 2016-07-01 00:00:00+00:00
8 quarter 2016-10-10 19:46:33.306158 +0000 UTC true 2016-10-01 00:00:00+00:00
9 month 2001-04-10 12:04:59 +0000 UTC true 2001-04-01 00:00:00+00:00
10 month 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-01 00:00:00+00:00
11 months 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-01 00:00:00+00:00
12 week 2001-04-10 12:04:59 +0000 UTC true 2001-04-09 00:00:00+00:00
13 weeks 2001-01-05 12:04:59 +0000 UTC true 2001-01-01 00:00:00+00:00
14 day 2001-04-10 12:04:59 +0000 UTC true 2001-04-10 00:00:00+00:00
15 day 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-10 00:00:00+00:00
16 days 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-10 00:00:00+00:00
24 hour 2001-04-10 12:04:59 +0000 UTC true 2001-04-10 12:00:00+00:00
25 hour 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-10 19:00:00+00:00
26 hour 2016-02-10 23:46:33.306158 +0000 UTC true 2016-02-10 23:00:00+00:00
27 hours 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-10 19:00:00+00:00
28 hours 2016-02-10 23:46:33.306158 +0000 UTC true 2016-02-10 23:00:00+00:00
29 minute 2001-04-10 12:04:59 +0000 UTC true 2001-04-10 12:04:00+00:00
30 minute 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-10 19:46:00+00:00
31 minutes 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-10 19:46:00+00:00
32 second 2001-04-10 12:04:59.234 +0000 UTC true 2001-04-10 12:04:59+00:00
33 second 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-10 19:46:33+00:00
34 seconds 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-10 19:46:33+00:00
35 millisecond 2001-04-10 12:04:59.234567 +0000 UTC true 2001-04-10 12:04:59.234+00:00
36 millisecond 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-10 19:46:33.306+00:00
37 milliseconds 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-10 19:46:33.306+00:00
38 microsecond 2001-04-10 12:04:59.345654 +0000 UTC true 2001-04-10 12:04:59.345654+00:00
39 microsecond 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-10 19:46:33.306158+00:00
40 microseconds 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-10 19:46:33.306158+00:00
45 decade 2001-04-10 12:04:59 +0000 UTC true 2000-01-01 00:00:00+00:00
46 decade -2015-02-10 19:46:33.306158 +0000 UTC true -2020-01-01 00:00:00+00:00
47 century 2016-02-10 19:46:33.306158 +0000 UTC true 2001-01-01 00:00:00+00:00
48 century -0003-02-10 19:46:33.306158 +0000 UTC true -0099-01-01 00:00:00+00:00
49 millennium 2016-02-10 19:46:33.306158 +0000 UTC true 2001-01-01 00:00:00+00:00
50 millennium -1003-02-10 19:46:33.306158 +0000 UTC true -1999-01-01 00:00:00+00:00
1 year 2001-04-10 12:04:59 +0000 UTC true 2001-01-01 00:00:00
2 year 2016-02-10 19:46:33.306158 +0000 UTC true 2016-01-01 00:00:00
3 years 2016-02-10 19:46:33.306158 +0000 UTC true 2016-01-01 00:00:00
4 quarter 2001-04-10 12:04:59 +0000 UTC true 2001-04-01 00:00:00
5 quarter 2016-02-10 19:46:33.306158 +0000 UTC true 2016-01-01 00:00:00
6 quarter 2016-05-10 19:46:33.306158 +0000 UTC true 2016-04-01 00:00:00
7 quarter 2016-09-09 19:46:33.306158 +0000 UTC true 2016-07-01 00:00:00
8 quarter 2016-10-10 19:46:33.306158 +0000 UTC true 2016-10-01 00:00:00
9 month 2001-04-10 12:04:59 +0000 UTC true 2001-04-01 00:00:00
10 month 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-01 00:00:00
11 months 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-01 00:00:00
12 week 2001-04-10 12:04:59 +0000 UTC true 2001-04-09 00:00:00
13 weeks 2001-01-05 12:04:59 +0000 UTC true 2001-01-01 00:00:00
14 day 2001-04-10 12:04:59 +0000 UTC true 2001-04-10 00:00:00
15 day 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-10 00:00:00
16 days 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-10 00:00:00
24 hour 2001-04-10 12:04:59 +0000 UTC true 2001-04-10 12:00:00
25 hour 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-10 19:00:00
26 hour 2016-02-10 23:46:33.306158 +0000 UTC true 2016-02-10 23:00:00
27 hours 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-10 19:00:00
28 hours 2016-02-10 23:46:33.306158 +0000 UTC true 2016-02-10 23:00:00
29 minute 2001-04-10 12:04:59 +0000 UTC true 2001-04-10 12:04:00
30 minute 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-10 19:46:00
31 minutes 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-10 19:46:00
32 second 2001-04-10 12:04:59.234 +0000 UTC true 2001-04-10 12:04:59
33 second 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-10 19:46:33
34 seconds 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-10 19:46:33
35 millisecond 2001-04-10 12:04:59.234567 +0000 UTC true 2001-04-10 12:04:59.234
36 millisecond 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-10 19:46:33.306
37 milliseconds 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-10 19:46:33.306
38 microsecond 2001-04-10 12:04:59.345654 +0000 UTC true 2001-04-10 12:04:59.345654
39 microsecond 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-10 19:46:33.306158
40 microseconds 2016-02-10 19:46:33.306158 +0000 UTC true 2016-02-10 19:46:33.306158
45 decade 2001-04-10 12:04:59 +0000 UTC true 2000-01-01 00:00:00
46 decade -2015-02-10 19:46:33.306158 +0000 UTC true -2020-01-01 00:00:00
47 century 2016-02-10 19:46:33.306158 +0000 UTC true 2001-01-01 00:00:00
48 century -0003-02-10 19:46:33.306158 +0000 UTC true -0099-01-01 00:00:00
49 millennium 2016-02-10 19:46:33.306158 +0000 UTC true 2001-01-01 00:00:00
50 millennium -1003-02-10 19:46:33.306158 +0000 UTC true -1999-01-01 00:00:00

query IBT
SELECT k, date_trunc(element, input::timestamptz) = date_trunc_result, date_trunc(element, input::timestamptz)::string
Expand Down Expand Up @@ -793,7 +793,7 @@ FROM ex WHERE date_trunc_result IS NOT NULL ORDER BY k
query T
SELECT (timestamp '2016-02-10 19:46:33.306157519')::string
----
2016-02-10 19:46:33.306158+00:00
2016-02-10 19:46:33.306158

query T
SELECT (timestamptz '2016-02-10 19:46:33.306157519')::string
Expand Down
Loading