cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Using a UDF in %sql?

BradSheridan
Valued Contributor

Afternoon everyone! I logged in hoping to see some suggestions but think maybe I need to reword the question a little 🙂

How can I create a UDF that converts '30000101' to timestamp and then use it in a query like below?

%sql

select

field1,

field2,

nvl(somedatefield, myUDF)

In other words, if the somedatefield in the source is null, always return 30000101 formatted as Timestamp

thanks!!

1 ACCEPTED SOLUTION

Accepted Solutions

BradSheridan
Valued Contributor

Got it working (but going to post a new question momentarily): I needed to use timestamp(date '3000-01-01) instead of to_timestamp

View solution in original post

1 REPLY 1

BradSheridan
Valued Contributor

Got it working (but going to post a new question momentarily): I needed to use timestamp(date '3000-01-01) instead of to_timestamp

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group