Github user dongjoon-hyun commented on a diff in the pull request:
https://github.com/apache/spark/pull/20057#discussion_r168930195
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/jdbc/PostgresDialect.scala ---
@@ -85,15 +85,24 @@ private object PostgresDialect extends JdbcDialect {
s"SELECT 1 FROM $table LIMIT 1"
}
+ override def isCascadingTruncateTable(): Option[Boolean] = Some(false)
+
/**
- * The SQL query used to truncate a table. For Postgres, the default
behaviour is to
- * also truncate any descendant tables. As this is a (possibly unwanted)
side-effect,
- * the Postgres dialect adds 'ONLY' to truncate only the table in question
- * @param table The name of the table.
- * @return The SQL query to use for truncating a table
- */
- override def getTruncateQuery(table: String): String = {
- s"TRUNCATE TABLE ONLY $table"
+ * The SQL query used to truncate a table. For Postgres, the default
behaviour is to
+ * also truncate any descendant tables. As this is a (possibly unwanted)
side-effect,
+ * the Postgres dialect adds 'ONLY' to truncate only the table in
question
+ * @param table The table to truncate
+ * @param cascade Whether or not to cascade the truncation. Default
value is the value of
+ * isCascadingTruncateTable()
+ * @return The SQL query to use for truncating a table
+ */
+ override def getTruncateQuery(
+ table: String,
+ cascade: Option[Boolean] = isCascadingTruncateTable): String = {
+ cascade match {
+ case Some(true) => s"TRUNCATE TABLE ONLY $table CASCADE"
--- End diff --
I believe you already these this in PostgreSQL.
To make it sure for us about using these `ONLY` and `CASCADE` at the same
time, could you share us the result of a manual test of this with PostgreSQL
tables, descendant, and foreign-key referenced tables here?
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]