Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ClickHouse CAST column AS SIGNED?

I have a table with column that contains timezone in format: +00:00
eg.:

tz
+04:30
+02:00
+10:00
-04:00

I can use CAST in MySQL: CAST(tz AS SIGNED) and it will give this result:

CAST(tz AS SIGNED)
4
2
10
-4

I tried to use toInt64 for ClickHouse, but it produce an exception.
How I can reach the same result with ClickHouse ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

SELECT
    arrayJoin(['+04:30', '-4:30', '10:00']) AS x,
    toInt64OrZero(extract(x, '(.*):')) AS y

Query id: 4b704281-649a-499e-906c-89873112c9e1

┌─x──────┬──y─┐
│ +04:30 │  4 │
│ -4:30  │ -4 │
│ 10:00  │ 10 │
└────────┴────┘
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading