sql-serverazurepysparkdatabricksreserved

Cant extract table data since table name "User" is a reserved name


So my problem is, I am trying to extract a table into this dataframe but I cant since the table named "User" is a reserved word... How could I go about this to get past the problem?

Thanks!

attachmentDf = (spark.read 
         .format("com.microsoft.sqlserver.jdbc.spark") 
         .option("url", azure_sql_url) 
         .option("databaseName", database_name) 
         .option("user", sql_user_name)
         .option("password", sql_password)
         .option("encrypt", "true") 
         .option("hostNameInCertificate", "*.database.windows.net")
         .option("dbtable", "dbo."+"User").load()
           )

Error message:

com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near the keyword 'User'.


Solution

  • Try putting square brackets around the table name (e.g. [dbo].[user]). That tells MS SQL to use the string as a field or table name.