From 94c4981586d60edf6b1b76d941429da6e3f88dfc Mon Sep 17 00:00:00 2001 From: Dave MacLeod <56599343+Dhghomon@users.noreply.github.com> Date: Tue, 23 Dec 2025 14:23:46 +0900 Subject: [PATCH] Show that table can't be removed if a view is using it --- .../doc-surrealql/statements/remove.mdx | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/content/doc-surrealql/statements/remove.mdx b/src/content/doc-surrealql/statements/remove.mdx index 8d9440265..5531be4dd 100644 --- a/src/content/doc-surrealql/statements/remove.mdx +++ b/src/content/doc-surrealql/statements/remove.mdx @@ -177,3 +177,45 @@ REMOVE PARAM IF EXISTS $author; REMOVE TABLE IF EXISTS article; ``` + +### Usage in table views + + + +A table used as a source for a table view cannot be removed until the table view itself has been removed. + +```surql +DEFINE TABLE pc; +DEFINE TABLE pc_agg AS SELECT count(), class FROM pc GROUP BY class; +CREATE |pc:3| SET class = "Wizard"; +CREATE |pc:10| SET class = "Warrior"; +SELECT * FROM pc_agg; +-- Error: pc_agg requires pc to work +REMOVE TABLE pc; +REMOVE TABLE pc_agg; +-- pc_agg is now gone, pc can be removed too +REMOVE TABLE pc; +``` + +The `SELECT * FROM pc_agg` query shows that the table view is pulling data from the `pc` table. As long as the `pc` table exists, `pc_agg` cannot be removed. + +```surql +-------- Query -------- + +[ + { + class: 'Warrior', + count: 10, + id: pc_agg:['Warrior'] + }, + { + class: 'Wizard', + count: 3, + id: pc_agg:['Wizard'] + } +] + +-------- Query -------- + +'Invalid query: Cannot delete table `pc` on which a view is defined, table(s) `pc_agg` are defined as a view on this table.' +``` \ No newline at end of file