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: 

SET a parameter in BEGIN END statement

oneill
New Contributor II

Hello,

How to set a parameter in a begin end statement. for exemple the following query fails : 

begin

SET ansi_mode = true;

end;

with Cannot resolve variable `ANSI_MODE` on search path `SYSTEM`.`SESSION`. SQLSTATE: 42883

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Vinay_M_R
Databricks Employee
Databricks Employee

Hello @oneill 

There is currently no supported workaround to dynamically change system/session parameters such as ansi_mode within a BEGIN ... END block in Databricks SQL procedures or scripts. Can you set these parameters before executing any procedural logic.

For example:

SET ANSI_MODE = true;
BEGIN
  -- procedural code here
END;

 

View solution in original post

2 REPLIES 2

Vinay_M_R
Databricks Employee
Databricks Employee

Hello @oneill 

There is currently no supported workaround to dynamically change system/session parameters such as ansi_mode within a BEGIN ... END block in Databricks SQL procedures or scripts. Can you set these parameters before executing any procedural logic.

For example:

SET ANSI_MODE = true;
BEGIN
  -- procedural code here
END;

 

oneill
New Contributor II

Hello, thanks for the reply. Yes, it is possible to execute the statement outside the block, but I wanted to make sure there wasn't a special syntax so that the block doesn't consider the parameter as a variable. We'll wait for an update to define parameters inside a begin...end block. There was SET VAR before SQL scripting possibilities. Maybe a SET PARAM inside a block.

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!

Sign Up Now