Flink SQL: Convert NULL Timestamp to YYYY-MM-DD HH:mm:ss String
In Flink SQL, you can use the DATE_FORMAT function to transform a TIMESTAMP column containing NULL values into a YYYY-MM-DD HH:mm:ss formatted string. Here's a practical example:
SELECT
CASE
WHEN your_timestamp_column IS NULL THEN NULL
ELSE DATE_FORMAT(your_timestamp_column, 'yyyy-MM-dd HH:mm:ss')
END AS formatted_timestamp
FROM
your_table;
In this example, 'your_timestamp_column' represents the name of the TIMESTAMP column containing NULL values, and 'your_table' represents the name of the table containing this column. The DATE_FORMAT function converts non-NULL TIMESTAMP values into the specified date and time format. If the value is NULL, it returns NULL.
Note that the parameter format of the DATE_FORMAT function can be customized based on your needs. In this example, 'yyyy-MM-dd HH:mm:ss' is used to transform the TIMESTAMP into a YYYY-MM-DD HH:mm:ss formatted string. Refer to the MySQL DATE_FORMAT function documentation for more options on date and time formatting.
原文地址: https://www.cveoy.top/t/topic/qyeh 著作权归作者所有。请勿转载和采集!