<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to run stored procedure in Azure Database for PostgreSQL using Azure Databricks Notebook in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-run-stored-procedure-in-azure-database-for-postgresql/m-p/103476#M41449</link>
    <description>&lt;P class="p1"&gt;To execute a PostgreSQL stored procedure from an Azure Databricks notebook, you need to follow these steps:&lt;/P&gt;
&lt;OL class="ol1"&gt;
&lt;LI class="li1"&gt;&lt;STRONG&gt;Required Libraries:&lt;/STRONG&gt;&lt;/LI&gt;
&lt;UL class="ul1"&gt;
&lt;LI class="li1"&gt;You need to install the psycopg2 library, which is a PostgreSQL adapter for Python. This can be done using the %pip install psycopg2 command in your Databricks notebook.&lt;/LI&gt;
&lt;/UL&gt;
&lt;LI class="li1"&gt;&lt;STRONG&gt;Connecting to Azure Database for PostgreSQL using ODBC:&lt;/STRONG&gt;&lt;/LI&gt;
&lt;UL class="ul1"&gt;
&lt;LI class="li1"&gt;You can use the psycopg2 library to establish a connection to your Azure Database for PostgreSQL. Here is an example of how to set up the connection:&lt;/LI&gt;
&lt;/UL&gt;
&lt;/OL&gt;
&lt;P class="p1"&gt;import psycopg2&lt;/P&gt;
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;conn = psycopg2.connect(&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;host="your_postgresql_host",&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;database="your_database_name",&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;user="your_username",&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;password="your_password"&lt;/P&gt;
&lt;P class="p1"&gt;)&lt;/P&gt;
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;&lt;STRONG&gt;Executing the PostgreSQL Stored Procedure:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL class="ul1"&gt;
&lt;LI class="li1"&gt;Once the connection is established, you can execute the stored procedure using a cursor object. Here is an example:&lt;/LI&gt;
&lt;/UL&gt;
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;cur = conn.cursor()&lt;/P&gt;
&lt;P class="p1"&gt;cur.execute("CALL your_stored_procedure_name()")&lt;/P&gt;
&lt;P class="p1"&gt;conn.commit()&lt;/P&gt;
&lt;P class="p1"&gt;cur.close()&lt;/P&gt;
&lt;P class="p1"&gt;conn.close()&lt;/P&gt;
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;Make sure to replace "your_postgresql_host", "your_database_name", "your_username", "your_password", and "your_stored_procedure_name" with your actual PostgreSQL host, database name, username, password, and stored procedure name respectively.&lt;/P&gt;</description>
    <pubDate>Sun, 29 Dec 2024 22:41:25 GMT</pubDate>
    <dc:creator>Alberto_Umana</dc:creator>
    <dc:date>2024-12-29T22:41:25Z</dc:date>
    <item>
      <title>How to run stored procedure in Azure Database for PostgreSQL using Azure Databricks Notebook</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-run-stored-procedure-in-azure-database-for-postgresql/m-p/103463#M41445</link>
      <description>&lt;P&gt;We have&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;Stored Procedure&lt;/STRONG&gt;&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;available in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;Azure Database for PostgreSQL&lt;/STRONG&gt;&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and we want to call or run or execute the postgreSQL stored procedures in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;Azure Databricks&lt;/STRONG&gt;&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;through Notebook&lt;/P&gt;&lt;P&gt;We are attempting to run PostgreSQL stored procedures, through Azure Databricks notebook and would need help how to execute a stored procedure. I would need clarity in below points&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;What are the required libraries that needs to be installed in Databricks cluster (if any)?&lt;/LI&gt;&lt;LI&gt;How to connect with Azure Database for PostgreSQL using ODBC?&lt;/LI&gt;&lt;LI&gt;How to Execute PostgreSQL stored procedure in Databricks?&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I am referring to below link,&lt;/P&gt;&lt;P&gt;&lt;A href="https://nachiketrajput44.medium.com/how-to-run-stored-procedure-in-azure-data-warehouse-using-databricks-caa912d123d5" rel="ugc nofollow" target="_blank"&gt;https://nachiketrajput44.medium.com/how-to-run-stored-procedure-in-azure-data-warehouse-using-databricks-caa912d123d5&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Let me know if anyone has step-by-step approach how to solve this issue.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Dec 2024 16:49:08 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-run-stored-procedure-in-azure-database-for-postgresql/m-p/103463#M41445</guid>
      <dc:creator>singhanuj2803</dc:creator>
      <dc:date>2024-12-29T16:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to run stored procedure in Azure Database for PostgreSQL using Azure Databricks Notebook</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-run-stored-procedure-in-azure-database-for-postgresql/m-p/103476#M41449</link>
      <description>&lt;P class="p1"&gt;To execute a PostgreSQL stored procedure from an Azure Databricks notebook, you need to follow these steps:&lt;/P&gt;
&lt;OL class="ol1"&gt;
&lt;LI class="li1"&gt;&lt;STRONG&gt;Required Libraries:&lt;/STRONG&gt;&lt;/LI&gt;
&lt;UL class="ul1"&gt;
&lt;LI class="li1"&gt;You need to install the psycopg2 library, which is a PostgreSQL adapter for Python. This can be done using the %pip install psycopg2 command in your Databricks notebook.&lt;/LI&gt;
&lt;/UL&gt;
&lt;LI class="li1"&gt;&lt;STRONG&gt;Connecting to Azure Database for PostgreSQL using ODBC:&lt;/STRONG&gt;&lt;/LI&gt;
&lt;UL class="ul1"&gt;
&lt;LI class="li1"&gt;You can use the psycopg2 library to establish a connection to your Azure Database for PostgreSQL. Here is an example of how to set up the connection:&lt;/LI&gt;
&lt;/UL&gt;
&lt;/OL&gt;
&lt;P class="p1"&gt;import psycopg2&lt;/P&gt;
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;conn = psycopg2.connect(&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;host="your_postgresql_host",&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;database="your_database_name",&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;user="your_username",&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;password="your_password"&lt;/P&gt;
&lt;P class="p1"&gt;)&lt;/P&gt;
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;&lt;STRONG&gt;Executing the PostgreSQL Stored Procedure:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL class="ul1"&gt;
&lt;LI class="li1"&gt;Once the connection is established, you can execute the stored procedure using a cursor object. Here is an example:&lt;/LI&gt;
&lt;/UL&gt;
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;cur = conn.cursor()&lt;/P&gt;
&lt;P class="p1"&gt;cur.execute("CALL your_stored_procedure_name()")&lt;/P&gt;
&lt;P class="p1"&gt;conn.commit()&lt;/P&gt;
&lt;P class="p1"&gt;cur.close()&lt;/P&gt;
&lt;P class="p1"&gt;conn.close()&lt;/P&gt;
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;Make sure to replace "your_postgresql_host", "your_database_name", "your_username", "your_password", and "your_stored_procedure_name" with your actual PostgreSQL host, database name, username, password, and stored procedure name respectively.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Dec 2024 22:41:25 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-run-stored-procedure-in-azure-database-for-postgresql/m-p/103476#M41449</guid>
      <dc:creator>Alberto_Umana</dc:creator>
      <dc:date>2024-12-29T22:41:25Z</dc:date>
    </item>
  </channel>
</rss>

