7.3.67. truncate — Groonga v9.1.1-76-g53aa7c4 documentation

# groonga - An open-source fulltext search engine and column store.

- 日本語

# 7.3.67. `truncate`

## 7.3.67.1. Summary

`truncate` command deletes all records from specified table or all values from specified column.

## 7.3.67.2. Syntax

This command takes only one required parameter:

    truncate target_name

New in version 4.0.9: `target_name` parameter can be used since 4.0.9. You need to use `table` parameter for 4.0.8 or earlier.

For backward compatibility, `truncate` command accepts `table` parameter. But it should not be used for newly written code.

## 7.3.67.3. Usage

Here is a simple example of `truncate` command against a table.

Execution example:

    table_create Users TABLE_PAT_KEY ShortText
    # [[0, 1337566253.89858, 0.000355720520019531], true]
    column_create Users score COLUMN_SCALAR Int32
    # [[0, 1337566253.89858, 0.000355720520019531], true]
    load --table Users
    [
    {"_key": "Alice",  "score": 2},
    {"_key": "Bob",    "score": 0},
    {"_key": "Carlos", "score": -1}
    ]
    # [[0, 1337566253.89858, 0.000355720520019531], 3]
    select Users
    # [
    #   [
    #     0,
    #     1337566253.89858,
    #     0.000355720520019531
    #   ],
    #   [
    #     [
    #       [
    #         3
    #       ],
    #       [
    #         [
    #           "_id",
    #           "UInt32"
    #         ],
    #         [
    #           "_key",
    #           "ShortText"
    #         ],
    #         [
    #           "score",
    #           "Int32"
    #         ]
    #       ],
    #       [
    #         1,
    #         "Alice",
    #         2
    #       ],
    #       [
    #         2,
    #         "Bob",
    #         0
    #       ],
    #       [
    #         3,
    #         "Carlos",
    #         -1
    #       ]
    #     ]
    #   ]
    # ]
    truncate Users
    # [[0, 1337566253.89858, 0.000355720520019531], true]
    select Users
    # [
    #   [
    #     0,
    #     1337566253.89858,
    #     0.000355720520019531
    #   ],
    #   [
    #     [
    #       [
    #         0
    #       ],
    #       [
    #         [
    #           "_id",
    #           "UInt32"
    #         ],
    #         [
    #           "_key",
    #           "ShortText"
    #         ],
    #         [
    #           "score",
    #           "Int32"
    #         ]
    #       ]
    #     ]
    #   ]
    # ]

Here is a simple example of `truncate` command against a column.

Execution example:

    table_create Users TABLE_PAT_KEY ShortText
    # [[0, 1337566253.89858, 0.000355720520019531], true]
    column_create Users score COLUMN_SCALAR Int32
    # [[0, 1337566253.89858, 0.000355720520019531], true]
    load --table Users
    [
    {"_key": "Alice",  "score": 2},
    {"_key": "Bob",    "score": 0},
    {"_key": "Carlos", "score": -1}
    ]
    # [[0, 1337566253.89858, 0.000355720520019531], 3]
    select Users
    # [
    #   [
    #     0,
    #     1337566253.89858,
    #     0.000355720520019531
    #   ],
    #   [
    #     [
    #       [
    #         3
    #       ],
    #       [
    #         [
    #           "_id",
    #           "UInt32"
    #         ],
    #         [
    #           "_key",
    #           "ShortText"
    #         ],
    #         [
    #           "score",
    #           "Int32"
    #         ]
    #       ],
    #       [
    #         1,
    #         "Alice",
    #         2
    #       ],
    #       [
    #         2,
    #         "Bob",
    #         0
    #       ],
    #       [
    #         3,
    #         "Carlos",
    #         -1
    #       ]
    #     ]
    #   ]
    # ]
    truncate Users.score
    # [[0, 1337566253.89858, 0.000355720520019531], true]
    select Users
    # [
    #   [
    #     0,
    #     1337566253.89858,
    #     0.000355720520019531
    #   ],
    #   [
    #     [
    #       [
    #         3
    #       ],
    #       [
    #         [
    #           "_id",
    #           "UInt32"
    #         ],
    #         [
    #           "_key",
    #           "ShortText"
    #         ],
    #         [
    #           "score",
    #           "Int32"
    #         ]
    #       ],
    #       [
    #         1,
    #         "Alice",
    #         0
    #       ],
    #       [
    #         2,
    #         "Bob",
    #         0
    #       ],
    #       [
    #         3,
    #         "Carlos",
    #         0
    #       ]
    #     ]
    #   ]
    # ]

## 7.3.67.4. Parameters

This section describes parameters of `truncate`.

### 7.3.67.4.1. Required parameters

There is required parameter, `target_name`.

#### 7.3.67.4.1.1. `target_name`

Specifies the name of table or column.

## 7.3.67.5. Return value

`truncate` command returns whether truncation is succeeded or not:

    [HEADER, SUCCEEDED_OR_NOT]

`HEADER`

> See Output format about `HEADER`.

`SUCCEEDED_OR_NOT`

> If command succeeded, it returns true, otherwise it returns false on error.