cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Parameterizing Snowflake query in Snaplogic

azvineth
New Contributor

I am trying to execute a Snowflake query to fetch some columns data in a table using Snowflake Execute snap.
Select โ€œidโ€, โ€œuser_nameโ€, โ€œuser_locationโ€, โ€œuser_emailโ€ from t_user where โ€œuser_locationโ€ = โ€˜Chennaiโ€™ order by โ€œidโ€;
Now in the above query I need to parameterize the filter used and so I introduced a pipeline paramter โ€œu_locโ€ in the pipeline properties and changed the query as below. But it shows query parsing failed error on validation.
โ€œSelect โ€œidโ€, โ€œuser_nameโ€, โ€œuser_locationโ€, โ€œuser_emailโ€ from t_user where โ€œuser_locationโ€ = 'โ€+_u_loc+โ€œโ€™ order by โ€œidโ€;โ€

5 REPLIES 5

bojanvelevski
Valued Contributor

Hi @azvineth,

Try the following:

"Select 'id', 'user_name', 'user_location', 'user_email' from t_user where 'user_location' = '"+_u_loc+"' order by 'id';"

If you place a mapper in front of the Snowflake Execute snap, youโ€™ll be able to validate the query and see how it looks before sending it to Snowflake. Just for debugging purposes.

Regards
Bojan

Supratim
Contributor III

@azvineth Can also try the below option -

"Select id, user_name, user_location, user_email from t_user where user_location = โ€˜%sโ€™ order by id ".sprintf(_u_loc)

@Supratim Nope. Throws the below error.
Failed to execute query: Select id, user_name, user_location, user_email from t_user where user_location = โ€˜Chennaiโ€™ order by id
Reason:
SQL compilation error: error line 1 at position 7 invalid identifier โ€˜IDโ€™

azvineth
New Contributor

@bojanvelevski That did not work. Got the below error.

Failed to execute query: Select โ€˜idโ€™, โ€˜user_nameโ€™, โ€˜user_locationโ€™, โ€˜user_emailโ€™ from t_user where โ€˜user_locationโ€™ = โ€˜Chennaiโ€™ order by โ€˜idโ€™
SQL compilation error:
syntax error line 1 at position 8 unexpected โ€˜โ€˜idโ€™โ€™