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

293 Views Asked by At

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'.

2

There are 2 best solutions below

0
JackLThornton On BEST ANSWER

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.

1
javisrk On

Since you are using a keyword as a table, you must enclose 'user' in brackets.

ex. dbo.[user]