Clear

Clear removes every row from a table but keeps the table definition in the catalog. It is equivalent to delete from without a where clause, but expressed as a dedicated statement.

Syntax

Railroad

cleartablename;

BNF

clear-stmt ::= "clear" "table" identifier ";"

Rules

  1. Clears all rows; the table schema and catalog entry remain. (phase: execute)
  2. Clearing a non-existent table is a static error. (phase: catalog)

Examples

Minimal

Table Place

Clear removes every row but leaves the table in place.

SQL

create table T;

insert into T ({"x": 1}, {"x": 2}, {"x": 3});

clear table T;

select * from T;

Result

[]

Compound

New Rows

A cleared table is still resolvable and accepts new rows.

SQL

create table T;

insert into T ({"x": 1});

clear table T;

insert into T ({"x": 9});

select * from T;

Result

[
  { "x": 9 }
]

Error cases

Clearing An

Clearing an undeclared table is a static error.

SQL

clear table Ghost;

Expected error: static

See also