SNOW-1569842: to_date() function requires column name for the optional fmt parameter
What is the current behavior?
to_date() function signature seems to indicate that only Column names are accepted for the optional fmt parameter
What is the desired behavior?
to_date() function should accept string literals in addition to column names
How would this improve snowflake-snowpark-python?
Feature parity with SQL
References, Other Background
https://docs.snowflake.com/en/sql-reference/functions/to_date#arguments
Hello @padhia ,
Thanks for raising the concern. In Snowpark functions, all parameters are via column name only, applicable to all snowpark functions. If you want to pass direct string literals values to to_date, you can try using SQL expression, example
` df = session.create_dataframe([("2021-07-01",)], schema=["date_string"])
df = df.select(expr("TO_DATE('2021-07-01')").alias("converted_date"))
result = df.collect() for row in result: print(row)`
Regards, Sujan
Hello Sujan,
Thank you for getting back. My comment was intended for the second parameter, the format specification. It's almost always the case that the format to convert to is already known. It'd therefore be convenient for the second parameter of the function to be a string literal rather than a Column specification, which requires one to use functions.lit to transform a simple literal string.
Hello @padhia ,
You are referring to the TO_DATE function in Snowflake SQL while in Snowpark, functions like to_date() are typically used within the DataFrame API and require functions.lit() when passing a literal. Snowpark functions follow a different API structure, and to_date() expects either a column reference or a literal wrapped in functions.lit(). If you are looking for behavior similar to SQL's TO_DATE, they need to explicitly use functions.lit() for string literals.
With this closing the ticket as its working as designed.
Regards, Sujan