How to replace ${param} by :param

ZD
New Contributor III

Hello,

We previously used ${param} in our SQL queries:

SELECT * FROM json.`${source_path}/file.json`

However, this syntax is now deprecated. The recommended approach is to use :param instead.

param.PNG

But when I attempt to replace ${param} with :param, I encounter the below error:

SELECT * FROM json.`:source_path/file.json`

java.net.URISyntaxException: Relative path in absolute URI: :source_path/file.json

How can I correctly reference the parameter in this case?

radothede
Valued Contributor II

Hi @ZD 

Please try this syntax in Your notebook for SQL:

%sql
declare _my_path = 'some_path';
select _my_path;

 

radothede_1-1753253774061.png

 

ZD
New Contributor III

The question is how to use this declared variable between backticks `_my_path` ?

SELECT * FROM json.`_my_path/file.json`

This does not work!

szymon_dybczak
Esteemed Contributor III

Hi @ZD ,

Try something like that:

SELECT *
FROM identifier(:source_path)

szymon_dybczak_0-1753261481613.png

 

 

ZD
New Contributor III

Hi @szymon_dybczak 

Thank you for the proposed solution. However, this does not meet my business needs as it does not offer a dynamic approach for replacing the base path when having multiple files and formats.

szymon_dybczak
Esteemed Contributor III

Hi @ZD ,

But it does, you can use it in following way. Define 3 parameters:

- file_format

- base_path

- file_name

And then concatenate those parameters inside identifier clause:

SELECT *
FROM identifier(:file_format || :base_path || :file_name)

szymon_dybczak_0-1753265184836.png


Or maybe I didn't understand your requirments properly.