Synapse: saveAsTable non-default database

Johan á Rogvi-Hansen 101 Reputation points
2022-09-22T11:25:59.317+00:00

Hi.

In a Synapse notebook I'm trying to write a data frame to the Synapse database with a lake which is not set as the default.

I've tried different ways of doing this, specifying the path too, but I get the same error message implying that I'm trying to write to the default lake (to which I don't have the write permission).

What is the correct syntax for writing to the Synapse Database with a non-default lake?

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
4,363 questions
{count} votes

1 answer

Sort by: Most helpful
  1. AnnuKumari-MSFT 30,676 Reputation points Microsoft Employee
    2022-09-26T09:14:30.917+00:00

    Hi @Johan á Rogvi-Hansen ,

    Thankyou for the question on Microsoft Q&A platform.

    As per my understanding, you are trying to write data from dataframe to lake database (non default DB).

    You can explicitly mention the database name in which you want to write the dataframe by providing the fully qualified tablename in saveAsTable function.

    I tried to reproduce your requirement. Here, I created a new database named 'DemoDB' .

    Afterwards, I am trying to read a .csv file from my ADLS and loaded it into a dataframe using the code df= spark.read.csv('<filepath>')

    Then, I am loading the dataframe content into table in DemoDB database using the following code:
    df.write.mode('overwrite').saveAsTable('demoDB.employees')

    244730-microsoftteams-image-2.png

    For more details, kindly check the following video: Analyze data with Server less Spark Pool in Azure Synapse Analytics

    Hope this will help. Please let us know if any further queries.

    ------------------------------

    • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you.
      Original posters help the community find answers faster by identifying the correct answer. Here is how
    • Want a reminder to come back and check responses? Here is how to subscribe to a notification
    • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators