cur.close()Ĭonn.close() Code language: Python ( python ) Calling a function example ![]() Therefore, you can use the execute() method of the cursor object to call a function as follows: cur.execute( "SELECT * FROM function_name( %s,%s) ",(value1,value2)) Code language: Python ( python )Īfter that, process the result set returned by the function using the fetchone(), fetchall(), or fetchmany() method.įinally, call the close() method of the cursor and connection objects to close the communication with the PostgreSQL database server. Internally, the callproc() method translates the function call and input values into the following statement: SELECT * FROM function_name(value1,value2) Code language: Python ( python ) cur.callproc('function_name', (value1,value2)) Code language: SQL (Structured Query Language) ( sql ) Then, pass the name of the function and the optional input values to the callproc() method of the cursor object. cur = conn.cursor() Code language: SQL (Structured Query Language) ( sql ) Next, create a new cursor by calling the cursor() method of the connection object. The connect() method returns a new instance of the connection class. conn = nnect(dsn) Code language: Python ( python ) To call a PostgreSQL function from a Python program, you use the following steps:įirst, create a new database connection to the PostgreSQL database server by calling the connect() function of the psycopg2 module. Calling a PostgreSQL function in Python steps ![]() ![]() Summary: in this tutorial, you will learn how to call PostgreSQL functions from a Python program.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |