varbinary in databricks and sql server

Shambhu Rai 1,411 Reputation points
2024-01-12T10:58:03.8033333+00:00

Hi Expert, there is different output in varbinary in sql and databricks. it should be same

sql server value convert(varbinary(4),('0000000')) output '0x30303030' 

Databricks value cast select cast('0000000' as binary) output :  'MDAwMDAwMA=='
Azure Databricks
Azure Databricks
An Apache Spark-based analytics platform optimized for Azure.
2,514 questions
{count} vote

1 answer

Sort by: Most helpful
  1. PRADEEPCHEEKATLA 90,641 Reputation points Moderator
    2024-01-16T01:03:53.01+00:00


    Shambhu Rai
    - Thanks for the question and using MS Q&A platform.

    Here are the equivalent data type support & mapping for SQL Server sources:

    User's image

    For more details, refer to Azure Databricks - Data types.

    Note: varbinary is not a supported data type in Azure Databricks.

    Instead, you can use the binary data type in Databricks, which is equivalent to the varbinary data type in SQL Server. To convert a string to binary in Databricks, you can use the unhex function. For example, to convert the string '0000000' to binary, you can use the following code:

    SELECT unhex('303030303030') as binary_value
    
    
    

    Here is the equivalent code in Azure Databricks:

    User's image

    Hope this helps. Do let us know if you any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.