Home > Blockchain >  Calling Snowflake stored procedure from Go driver
Calling Snowflake stored procedure from Go driver

Time:08-29

I have a stored procedure in Snowflake called SP_MERGE_ASSETS. I can call it from the Snowflake console by doing this:

CALL MY_DATABASE.MY_SCHEMA.sp_merge_assets(0)

This works and does exactly what I expect it to. However, when I try the exact same procedure from Snowflake's Go library:

query := "CALL MY_DATABASE.MY_SCHEMA.sp_merge_assets(?)"
_, err := client.db.ExecContext(ctx, query, 0)

I get an SQL compilation error stating, Unknown user-defined function MY_DATABASE.MY_SCHEMA.SP_MERGE_ASSETS.

I suppose this makes sense as there isn't a UDF named "MY_DATABASE.MY_SCHEMA.SP_MERGE_ASSETS" defined in my account. But this error masks the actual problem: my stored procedure isn't being called. What am I doing wrong here?

CodePudding user response:

It turns out that, unlike in SQL server, calling a stored procedure in Snowflake requires using the QueryContext function instead of the ExecContext function. If you use ExecContext, Snwoflake will interpret the query as a call to a user-defined function. Changing the code to

query := "CALL MY_DATABASE.MY_SCHEMA.sp_merge_assets(?)"
_, err := client.db.QueryContext(ctx, query, 0)

fixed the issue.

  • Related