3

I have created stored procedure in snowflake which is executed fine in snowflake UI and also from server by using snowsql. Now I want to execute procedure from python program, I tried to execute from python, here are the steps that I have followed:

  1. establish the connection to snowflake ( successfully able to connect.)

cs = ctx.cursor()

  1. Used appropriate role,warehouse,database and schema.
  2. tried to execute procedure like this:

cs.execute("call test_proc('value1', 'value2')")   
x = cs.fetchall() 
print(x)

But getting an erorr:

snowflake.connector.errors.ProgrammingError: 002140 (42601): SQL compilation error: Unknown function test_proc

Can you please help me to resolve this problem.

Thanks,

2 Answers 2

5

When connecting to Snowflake using Python connector you could define DATABASE/SCHEMA

conn = snowflake.connector.connect(
                user=USER,
                password=PASSWORD,
                account=ACCOUNT,
                warehouse=WAREHOUSE,
                database=DATABASE,
                schema=SCHEMA
                );

Once you have it set up, you could call your stored procedure without using fully-qualified name:

cs.execute("call test_proc('value1', 'value2')");

Alternative way is:

Using the Database, Schema, and Warehouse

Specify the database and schema in which you want to create tables. Also specify the warehouse that will provide resources for executing DML statements and queries.

For example, to use the database testdb, schema testschema and warehouse tiny_warehouse (created earlier):

conn.cursor().execute("USE WAREHOUSE tiny_warehouse_mg")
conn.cursor().execute("USE DATABASE testdb_mg")
conn.cursor().execute("USE SCHEMA testdb_mg.testschema_mg")
Sign up to request clarification or add additional context in comments.

Comments

0

Actually, I have to have command like this

cs.execute("call yourdbname.schemaname.test_proc('value1', 'value2')")

and It is working as expected.

Thanks

1 Comment

Had you connected to the DB and schema in your connection string, your first attempt would've worked, as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.