One
One

Reputation: 1

Access PostgreSQL from Azure Synapse Notebook

PostgreSQL setup in Azure, and I want to create tables, load/read data from Postgres DB using Synapse notebook(Pyspark). How can I do it?

Tried doing using connection string, other is there any other way?

Upvotes: 0

Views: 990

Answers (1)

Utkarsh Pal
Utkarsh Pal

Reputation: 4544

You can use JDBC driver to connect with Azure PostgreSQL database in Synapse PySpark Notebook.

Change the database configuration as per your database.

df = spark.read \
    .format("jdbc") \
    .option("url", "jdbc:postgresql://<servername>:5432/<databasename>") \
    .option("dbtable", <"tablename">) \
    .option("user", <"username">) \
    .option("password", <"password">) \
    .option("driver", "org.postgresql.Driver") \
    .load()

df.printSchema()

Upvotes: 0

Related Questions