7.3.71. truncate#

7.3.71.1. 概要#

truncate コマンドは指定したテーブルのレコードをすべて削除します。カラムを指定した場合はカラムの値をすべて削除します。

7.3.71.2. 構文#

このコマンドの引数は1つで必須です:

truncate target_name

バージョン 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.71.3. 使い方#

以下はテーブルに対して truncate コマンドを実行する簡単な使用例です。

実行例:

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"
#         ]
#       ]
#     ]
#   ]
# ]

以下はカラムに対して truncate コマンドを実行する簡単な使用例です。

実行例:

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.71.4. 引数#

このセクションでは truncate の引数について説明します。

7.3.71.4.1. 必須引数#

target_name だけが必須の引数です。

7.3.71.4.1.1. target_name#

テーブル名またはカラム名を指定します。

7.3.71.5. 戻り値#

truncate コマンドは全削除が成功したかどうかを返します。:

[HEADER, SUCCEEDED_OR_NOT]

HEADER

HEADER については 出力形式 を参照してください。

SUCCEEDED_OR_NOT

コマンドの実行が成功するとtrueを返します。失敗するとエラーとしてfalseを返します。