Forum Discussion

abhidotnet's avatar
abhidotnet
Advocate II
1 year ago
Solved

Issue with Date Casting in Fabric SQL UDF: read_from_sql_db Fails with InternalServerError

I'm working in a Microsoft Fabric workspace and using a user-defined function (UDF) to query a Fabric SQL database and return results as a pandas DataFrame. The function is defined as follows: impo...
  • v-ssriganesh's avatar
    1 year ago

    Hello abhidotnet,
    Thank you for reaching out to the Microsoft Fabric Community Forum. The issue with casting dates in your UDF likely stems from how the Fabric SQL connector handles DATE types when converting to a pandas DataFrame. Since the query works in the SQL endpoint, try these workarounds:

    • Remove CAST or TRY_CAST from your query and convert the [Expiration Date] column to a datetime in pandas using a post-processing step.
    • In your SQL query, convert the date to a string format (e.g., YYYY-MM-DD) using CONVERT(VARCHAR, [Expiration Date], 23), then parse it to a datetime in pandas.
    • Verify the [Expiration Date] column in the SQL endpoint for NULL or invalid values that might cause issues.

    If you have any further questions, please don't hesitate to contact us through the community. We are happy to assist you.

    Best Regards,
    Ganesh Singamshetty.