Skip to content

feat(sql): support truncate table if exists#5780

Closed
aleksandarskrbic wants to merge 22 commits intoquestdb:masterfrom
aleksandarskrbic:aleksandarskrbic/feat/truncate-table-if-exists
Closed

feat(sql): support truncate table if exists#5780
aleksandarskrbic wants to merge 22 commits intoquestdb:masterfrom
aleksandarskrbic:aleksandarskrbic/feat/truncate-table-if-exists

Conversation

@aleksandarskrbic
Copy link
Copy Markdown

Implements: #5763

);

// this query will fail silently because z does not exists
execute("truncate table if exists x, y, z");
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What behaviour is expected here?
For example in this query if x,y tables are present and z is not, to we want to execute truncate on existing tables and just ignore z.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect this to fail with invalid syntax.
Truncating multiple tables in one statement is a very unusual feature; we do not need to have it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, just wanted to be sure. Thanks!

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jun 24, 2025

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@ideoma
Copy link
Copy Markdown
Collaborator

ideoma commented Jun 30, 2025

Please fix the test failure:

https://dev.azure.com/questdb/questdb/_build/results?buildId=162758&view=ms.vss-test-web.build-test-results-tab&runId=528112&resultId=106043&paneView=debug

java.lang.AssertionError: 
expected:<count
0
> but was:<count
10
>
	at [email protected]/org.junit.Assert.fail(Assert.java:89)
	at [email protected]/org.junit.Assert.failNotEquals(Assert.java:835)
	at [email protected]/org.junit.Assert.assertEquals(Assert.java:120)
	at io.questdb.test/io.questdb.test.tools.TestUtils.assertEquals(TestUtils.java:526)
	at io.questdb.test/io.questdb.test.tools.TestUtils.assertEquals(TestUtils.java:509)
	at io.questdb.test/io.questdb.test.tools.TestUtils.assertCursor(TestUtils.java:228)
	at io.questdb.test/io.questdb.test.AbstractCairoTest.assertCursor(AbstractCairoTest.java:223)
	at io.questdb.test/io.questdb.test.AbstractCairoTest.assertCursor(AbstractCairoTest.java:190)
	at io.questdb.test/io.questdb.test.AbstractCairoTest.assertCursor(AbstractCairoTest.java:854)
	at io.questdb.test/io.questdb.test.AbstractCairoTest.assertFactoryCursor(AbstractCairoTest.java:1666)
	at io.questdb.test/io.questdb.test.AbstractCairoTest.assertQueryNoLeakCheck(AbstractCairoTest.java:1785)
	at io.questdb.test/io.questdb.test.AbstractCairoTest.assertQueryFullFatNoLeakCheck(AbstractCairoTest.java:1770)
	at io.questdb.test/io.questdb.test.AbstractCairoTest.lambda$assertQuery$15(AbstractCairoTest.java:1711)
	at io.questdb.test/io.questdb.test.AbstractCairoTest.lambda$assertMemoryLeak$8(AbstractCairoTest.java:1076)
	at io.questdb.test/io.questdb.test.tools.TestUtils.assertMemoryLeak(TestUtils.java:738)
	at io.questdb.test/io.questdb.test.AbstractCairoTest.assertMemoryLeak(AbstractCairoTest.java:1073)
	at io.questdb.test/io.questdb.test.AbstractCairoTest.assertMemoryLeak(AbstractCairoTest.java:1056)
	at io.questdb.test/io.questdb.test.AbstractCairoTest.assertQuery(AbstractCairoTest.java:1711)
	at io.questdb.test/io.questdb.test.griffin.TruncateTest.lambda$testTableIfExist$22(TruncateTest.java:690)
	at io.questdb.test/io.questdb.test.AbstractCairoTest.lambda$assertMemoryLeak$8(AbstractCairoTest.java:1076)
	at io.questdb.test/io.questdb.test.tools.TestUtils.assertMemoryLeak(TestUtils.java:738)
	at io.questdb.test/io.questdb.test.AbstractCairoTest.assertMemoryLeak(AbstractCairoTest.java:1073)
	at io.questdb.test/io.questdb.test.AbstractCairoTest.assertMemoryLeak(AbstractCairoTest.java:1056)
	at io.questdb.test/io.questdb.test.griffin.TruncateTest.testTableIfExist(TruncateTest.java:637)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at [email protected]/org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at [email protected]/org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at [email protected]/org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at [email protected]/org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at [email protected]/org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at [email protected]/org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at [email protected]/org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:61)
	at [email protected]/org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:299)
	at [email protected]/org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:293)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.lang.Thread.run(Thread.java:840)

@aleksandarskrbic aleksandarskrbic requested a review from ideoma July 2, 2025 12:06
@aleksandarskrbic
Copy link
Copy Markdown
Author

aleksandarskrbic commented Jul 8, 2025

@ideoma I see a bunch of PR related to this issue were submitted 2 weeks after my solution, and one of them already got approved. Guess this can be closed.

@bluestreak01
Copy link
Copy Markdown
Member

work merged into #6020

thank you @aleksandarskrbic we will acknowledge your contribution in the release notes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants