How do I fix the syntax error for truncating a table when I used the proper syntax

5,130 views
Skip to first unread message

gabjos

unread,
Feb 15, 2010, 2:34:22 PM2/15/10
to H2 Database
I type: truncate table test

The table does exist and I own it. But I keep getting the following
error:


I don't know what to do. Please help.

statement TRUNCATE TABLE FROM[*] test ; expected identifier; SQL
statement:
truncate table FROM test [42001-63]
org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement TRUNCATE
TABLE FROM[*] test ; expected identifier; SQL statement:
truncate table FROM test [42001-63]
at org.h2.message.Message.getSQLException(Message.java:89)
at org.h2.message.Message.getSQLException(Message.java:93)
at org.h2.message.Message.getSyntaxError(Message.java:103)
at org.h2.command.Parser.readIdentifierWithSchema(Parser.java:
2263)
at org.h2.command.Parser.readTableOrView(Parser.java:3906)
at org.h2.command.Parser.parseTruncate(Parser.java:888)
at org.h2.command.Parser.parsePrepared(Parser.java:381)
at org.h2.command.Parser.parse(Parser.java:264)
at org.h2.command.Parser.parse(Parser.java:236)
at org.h2.command.Parser.prepareCommand(Parser.java:208)
at org.h2.engine.Session.prepareLocal(Session.java:173)
at org.h2.server.TcpServerThread.process(TcpServerThread.java:
176)
at org.h2.server.TcpServerThread.run(TcpServerThread.java:97)
at java.lang.Thread.run(Unknown Source)

at org.h2.engine.SessionRemote.done(SessionRemote.java:289)
at org.h2.command.CommandRemote.prepare(CommandRemote.java:54)
at org.h2.command.CommandRemote.<init>(CommandRemote.java:37)
at org.h2.engine.SessionRemote.prepareCommand(SessionRemote.java:
237)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:
961)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:143)
at org.h2.server.web.WebThread.getResult(WebThread.java:1392)
at org.h2.server.web.WebThread.query(WebThread.java:1054)
at org.h2.server.web.WebThread.process(WebThread.java:375)
at org.h2.server.web.WebThread.processRequest(WebThread.java:131)
at org.h2.server.web.WebThread.run(WebThread.java:158)

Thomas Mueller

unread,
Feb 15, 2010, 2:37:30 PM2/15/10
to h2-da...@googlegroups.com
Hi,

It's "TRUNCATE TABLE test". See also
http://www.h2database.com/html/grammar.html#truncate_table

Regards,
Thomas

Kerry Sainsbury

unread,
Feb 15, 2010, 2:44:50 PM2/15/10
to h2-da...@googlegroups.com
On Tue, Feb 16, 2010 at 8:34 AM, gabjos <sikyala...@bah.com> wrote:
I type: truncate table test


Hmmm. It works for me without any error.

create table test(i int);
truncate table test;
drop table test;

Are you SURE you're typing "truncate table test"?

Cheers
Kerry

 

--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To post to this group, send email to h2-da...@googlegroups.com.
To unsubscribe from this group, send email to h2-database...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/h2-database?hl=en.


gabjos

unread,
Feb 15, 2010, 2:47:07 PM2/15/10
to H2 Database
That is exactly what I type and I keep getting the same errors. Now
when I type create table test1 as select * from test I get a internet
explorer error: A script on this page is causing Internet Explorer to
run slowly. If it continues to run, your computer may become
unresponsive. Do you want to abort the script.

I don't know if this has anything to do with why the database is
complaining of syntax errors. But I clicked yes to abort it and it has
come back again. I am not running any scripts on the database. So I
don't know where this error is coming from.

On Feb 15, 2:37 pm, Thomas Mueller <thomas.tom.muel...@gmail.com>
wrote:

Thomas Mueller

unread,
Feb 15, 2010, 2:49:18 PM2/15/10
to h2-da...@googlegroups.com
Hi,

> That is exactly what I type

No, you wrote:

TRUNCATE TABLE FROM test
not
TRUNCATE TABLE test

By the way, consider upgrading to a more recent version of H2. You are
using version 1.0.63.

Regards,
Thomas

gabjos

unread,
Feb 15, 2010, 3:04:19 PM2/15/10
to H2 Database
sorry i put the wrong error message here is the error:

truncate table test

Cannot truncate PUBLIC.test [90106-63]
org.h2.jdbc.JdbcSQLException: Cannot truncate PUBLIC.test [90106-63]


at org.h2.message.Message.getSQLException(Message.java:89)
at org.h2.message.Message.getSQLException(Message.java:93)

at org.h2.message.Message.getSQLException(Message.java:71)
at org.h2.command.ddl.TruncateTable.update(TruncateTable.java:30)
at org.h2.command.CommandContainer.update(CommandContainer.java:
64)
at org.h2.command.Command.executeUpdate(Command.java:122)
at org.h2.server.TcpServerThread.process(TcpServerThread.java:
241)


at org.h2.server.TcpServerThread.run(TcpServerThread.java:97)
at java.lang.Thread.run(Unknown Source)

at org.h2.engine.SessionRemote.done(SessionRemote.java:289)
at org.h2.command.CommandRemote.executeUpdate(CommandRemote.java:
164)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:155)


at org.h2.server.web.WebThread.getResult(WebThread.java:1392)
at org.h2.server.web.WebThread.query(WebThread.java:1054)
at org.h2.server.web.WebThread.process(WebThread.java:375)
at org.h2.server.web.WebThread.processRequest(WebThread.java:131)
at org.h2.server.web.WebThread.run(WebThread.java:158)

On Feb 15, 2:49 pm, Thomas Mueller <thomas.tom.muel...@gmail.com>
wrote:

Kerry Sainsbury

unread,
Feb 15, 2010, 3:15:46 PM2/15/10
to h2-da...@googlegroups.com
How do you create test?

Is it definitely a table? (not a view?)

Can you provide a complete example?

Cheers
Kerry

Thomas Mueller

unread,
Feb 15, 2010, 4:08:46 PM2/15/10
to h2-da...@googlegroups.com
Hi,

Tables with referential integrity constraints can not be truncated.
Also, system tables and view can not be truncated.

See also:
http://www.h2database.com/javadoc/org/h2/constant/ErrorCode.html#c90106
or use the Error Analyzer:
http://www.h2database.com/html/sourceError.html

Regards,
Thomas

gabjos

unread,
Feb 15, 2010, 5:44:32 PM2/15/10
to H2 Database
When I was trying to find out what the primary key for the table in
question I was given the following query:

select column_name from information_schema.indexes
where table_schema = 'PUBLIC'
and table_name='TEST'
and primary_key

I executed it on my table and since then I have been able to perform
any dml on it. Is there a way to undo this?

On Feb 15, 4:08 pm, Thomas Mueller <thomas.tom.muel...@gmail.com>
wrote:

gabjos

unread,
Feb 15, 2010, 5:45:21 PM2/15/10
to H2 Database
create test2 as select * from test

> > h2-database...@googlegroups.com<h2-database%2Bunsubscribe@googlegr­oups.com>


> > .
> > For more options, visit this group at

> >http://groups.google.com/group/h2-database?hl=en.- Hide quoted text -
>
> - Show quoted text -

Kerry Sainsbury

unread,
Feb 15, 2010, 6:21:18 PM2/15/10
to h2-da...@googlegroups.com
Dude.... that's a SELECT statement. It hasn't changed anything. Drop your "test" table and start again.


--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To post to this group, send email to h2-da...@googlegroups.com.
To unsubscribe from this group, send email to h2-database...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages