Grevioos
Grevioos

Reputation: 405

Is it possible to delete rows using JDBC?

Using spark jdbc connection, I am able to either read or write data. For example:

app_project_model_df = (
  sqlContext.read.format("jdbc")
  .option("url",sqlURL)
  .option("driver","com.microsoft.sqlserver.jdbc.SQLServerDriver")
  .option("dbtable","app.projectmodel")
  .option("user", dbuser)
  .option("password", dbpassword)
  .load()
)

However, is it possible to perform other SQL queries the very same way? Let's say delete from app.projectmodel where key = 6. Or do I need to use pure python for that?

I wasn't able to find any documentation on that. Thank you in advance.

Upvotes: 0

Views: 823

Answers (2)

Sanket9394
Sanket9394

Reputation: 2091

Adding extra details over @thebluephantom's answer.

According to spark's jdbc docs ,

If you write a query / dbtable -> <user_specified_query>

Then spark will run a query like :

SELECT <columns> FROM (<user_specified_query>) spark_gen_alias

One can fire any query that is supported by the DB's SQL Engine's FROM sub-query. So, DELETE FROM is not supported within FROM.

Upvotes: 1

Ged
Ged

Reputation: 18098

No, unless own implementation via forEachPartition for DF.

Upvotes: 0

Related Questions