views:

71

answers:

2

Can we classify/say that TRUNCATE belongs to/falls under DML statement?

Check here for PostgreSQL TRUNCATE compatibility.

NOTE: TRUNCATE is part of SQL standard ANSI SQL 2008 - F200

+1  A: 

I would say it's a DML statement in PostgreSQL: PostgreSQL has a TRUNCATE trigger but PostgreSQL doesn't have DDL triggers. So it can't be a DDL statement.

It acquires an ACCESS EXCLUSIVE lock on each table it operates on and it's not MVCC-safe but it's transactionsafe and you can do a rollback.

The ability to fire triggers for TRUNCATE is a PostgreSQL extension of the SQL standard.

Frank Heikens
@Frank: May be this is off-topic from my original question, is it a DDL statement in Oracle? Any ideas/comments?
Gnanam
You should ask an Oracle DBA, I don't have an opinion about it: lack of knowledge.
Frank Heikens
orafaq says it's DDL: http://www.orafaq.com/faq/difference_between_truncate_delete_and_drop_commands
Frank Heikens
@Frank: Thanks for sharing that link. So based on what I've understood from here, can we say that classification of TRUNCATE statement as DDL or DML would be mainly decided based on the factor that whether the transaction is allowed to `ROLLBACK` or not?
Gnanam
It depends on your database, there is not a single correct answer, DDL and DML are both correct: DDL in Oracle, DML in PostgreSQL. ROLLBACK can be used for almost everything in PostgreSQL, almost everything is transaction safe.
Frank Heikens
A: 

As TRUNCATE manipulates data and does not change any definition, I clearly see it as a DML statement.

a_horse_with_no_name