Skip to content

Feature: support variant cast to timestamp_tz #19034

@TCeason

Description

@TCeason

Summary

:) create or replace table t(c variant);

:) insert into t values('{"a":"2022-02-02 00:01:22+08:00"}');

╭─────────────────────────╮
│ number of rows inserted │
│          UInt64         │
├─────────────────────────┤
│                       1 │
╰─────────────────────────╯

:) select try_parse_json(c):a from t;

╭─────────────────────────────╮
│     try_parse_json(c):a     │
│      Nullable(Variant)      │
├─────────────────────────────┤
│ "2022-02-02 00:01:22+08:00" │
╰─────────────────────────────╯
1 row read in 0.043 sec. Processed 1 row, 55 B (23.26 rows/s, 1.25 KiB/s)

-- should success
:) select try_parse_json(c):a::timestamp_tz from t;
error: APIError: QueryFailed: [1006]unable to cast type `Variant` to type `TimestampTz`, during run expr: `CAST(get_by_keypath(try_parse_json(t.c (#0)), '{"a"}') AS TimestampTz NULL)`

-- Now we use this way 
:) select try_parse_json(c):a::String::timestamp_tz from t;
╭──────────────────────────────────╮
│        try_parse_json(c):a       │
│      Nullable(Timestamp_Tz)      │
├──────────────────────────────────┤
│ 2022-02-02 00:01:22.000000 +0800 │
╰──────────────────────────────────╯
1 row read in 0.056 sec. Processed 1 row, 55 B (17.86 rows/s, 982 B/s)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions