TRY_TO_DATE with pattern?

依然范特西╮ 提交于 2021-02-10 05:31:23

问题


Snowflake has a TO_DATE(string, pattern) function, but currently has no TRY_TO_DATE version of the function with the same signature. While we've built a javascript parsing function as a workaround, it has abysmal performance due to its complexity and the fact that it's performance could never measure against a real native function.

Is there a roadmap for the availability of such native function? Is there a community voting board to prioritize such function?


回答1:


Although there is not a parameter for this function, you can set DATE_INPUT_FORMAT to force a pattern for TRY_TO_DATE function:

ALTER SESSION SET DATE_INPUT_FORMAT = 'YYYY-MM-DD';
SELECT TRY_TO_DATE('2020-04-05'); -- will return a date value

ALTER SESSION SET DATE_INPUT_FORMAT = 'DD-MM-YYYY';
SELECT TRY_TO_DATE('2020-04-05'); -- will return NULL

https://docs.snowflake.com/en/sql-reference/parameters.html#date-input-format

You can use Snowflake Ideas to suggest and vote for new features:

https://community.snowflake.com/s/ideas




回答2:


Release Notes - August 3-6, 2020

TRY_TO_DATE(), TRY_TO_TIME(), and TRY_TO_TIMESTAMP() Functions: Support Added for Optional Format Specifier

With this release, the TRY_TO_DATE(), TRY_TO_TIME(), and the TRY_TO_TIMESTAMP() family of functions support an optional format specifier, similar to the corresponding TO_DATE(), TO_TIME(), and TO_TIMESTAMP() functions.


TRY_TO_DATE

A special version of TO_DATE , DATE that performs the same operation (i.e. converts an input expression to a date), but with error-handling support (i.e. if the conversion cannot be performed, it returns a NULL value instead of raising an error).

Syntax

TRY_TO_DATE( <string_expr> [, <format> ] )


来源:https://stackoverflow.com/questions/61542450/try-to-date-with-pattern

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!