0

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

pltc
  • 5,836
  • 1
  • 13
  • 31
Lasse
  • 17
  • 9

2 Answers2

2

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.

pltc
  • 5,836
  • 1
  • 13
  • 31
JackLThornton
  • 375
  • 3
  • 14
1

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

ex. dbo.[user]

pltc
  • 5,836
  • 1
  • 13
  • 31
javisrk
  • 582
  • 4
  • 19