[Wranglers] Passing a table name as a variable to Snowflake Stored Procedure

Ali, Saqib docbook.xml at gmail.com
Fri Jan 31 04:28:31 UTC 2025


Looks like for table names we have to use the IDENTIFIER() keyword as follows:

CREATE OR REPLACE PROCEDURE SP__INSERT_TO_CUSTOMERS(table_name varchar)
RETURNS string
LANGUAGE SQL
AS

BEGIN

insert into IDENTIFIER(:table_name) (customer_name)
select distinct
customer_name
from orders;

RETURN ‘SUCCESS’;
END;




On Wed, Jan 29, 2025 at 2:44 PM Ali, Saqib <docbook.xml at gmail.com> wrote:

> I am trying to define a Stored Procedure in Snowflake as follows. But it
> is erroring out on the variable binding for :table_name. Error: Syntax
> error: unexpected 'into'.
>
> How do I achieve this?
>
> CREATE OR REPLACE PROCEDURE SP__INSERT_TO_CUSTOMERS(table_name varchar)
>   RETURNS string
>   LANGUAGE SQL
> AS
>
> BEGIN
>
> insert into :table_name (customer_name)
>     select distinct
>       customer_name
>     from orders;
>
> RETURN 'SUCCESS';
> END;
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://analyticsengineering.net/pipermail/wranglers/attachments/20250130/165dcd04/attachment.htm>


More information about the Wranglers mailing list