7.3.22. delete — Groonga v14.1.2 documentation

Skip to main content
`Ctrl`+`K`

# 7.3.22. `delete`

## 7.3.22.1. Summary

`delete` command deletes specified record of table.

### 7.3.22.1.1. Cascade delete

There is a case that multiple table is associated. For example, the key of one table are referenced by other table’s records. In such a case, if you delete the key of one table, other table’s records are also removed.

Note that the type of other table’s column is COLUMN_VECTOR, only the value of referencing key is removed from the vector value.

## 7.3.22.2. Syntax

    delete table [key [id [filter]]]

## 7.3.22.3. Usage

Here are a schema definition and sample data to show usage.

Delete the record from Entry table which has “2” as the key.

Execution example:

    delete Entry 2
    # [[0,1337566253.89858,0.000355720520019531],true]
    select Entry
    # [
    #   [
    #     0,
    #     1337566253.89858,
    #     0.000355720520019531
    #   ],
    #   [
    #     [
    #       [
    #         1
    #       ],
    #       [
    #         [
    #           "_id",
    #           "UInt32"
    #         ],
    #         [
    #           "_key",
    #           "UInt32"
    #         ],
    #         [
    #           "status",
    #           "ShortText"
    #         ]
    #       ],
    #       [
    #         1,
    #         1,
    #         "OK"
    #       ]
    #     ]
    #   ]
    # ]

Here is the example about cascaded delete.

The country column of Users table associates with Country table.

“Cascaded delete” removes the records which matches specified key and refers that key.

Execution example:

    table_create Country TABLE_HASH_KEY ShortText
    # [[0,1337566253.89858,0.000355720520019531],true]
    table_create Users TABLE_HASH_KEY UInt32
    # [[0,1337566253.89858,0.000355720520019531],true]
    column_create Users name COLUMN_SCALAR ShortText
    # [[0,1337566253.89858,0.000355720520019531],true]
    column_create Users country COLUMN_SCALAR Country
    # [[0,1337566253.89858,0.000355720520019531],true]
    load --table Users
    [
    {"_key": 1, "name": "John", country: "United States"}
    {"_key": 2, "name": "Mike", country: "United States"}
    {"_key": 3, "name": "Takashi", country: "Japan"}
    {"_key": 4, "name": "Hanako", country: "Japan"}
    ]
    # [[0,1337566253.89858,0.000355720520019531],4]
    load --table Country
    [
    {"_key": "United States"}
    {"_key": "Japan"}
    ]
    # [[0,1337566253.89858,0.000355720520019531],2]
    delete Country "United States"
    # [[0,1337566253.89858,0.000355720520019531],true]
    select Country
    # [
    #   [
    #     0,
    #     1337566253.89858,
    #     0.000355720520019531
    #   ],
    #   [
    #     [
    #       [
    #         1
    #       ],
    #       [
    #         [
    #           "_id",
    #           "UInt32"
    #         ],
    #         [
    #           "_key",
    #           "ShortText"
    #         ]
    #       ],
    #       [
    #         2,
    #         "Japan"
    #       ]
    #     ]
    #   ]
    # ]
    select Users
    # [
    #   [
    #     0,
    #     1337566253.89858,
    #     0.000355720520019531
    #   ],
    #   [
    #     [
    #       [
    #         4
    #       ],
    #       [
    #         [
    #           "_id",
    #           "UInt32"
    #         ],
    #         [
    #           "_key",
    #           "UInt32"
    #         ],
    #         [
    #           "country",
    #           "Country"
    #         ],
    #         [
    #           "name",
    #           "ShortText"
    #         ]
    #       ],
    #       [
    #         1,
    #         1,
    #         "",
    #         "John"
    #       ],
    #       [
    #         2,
    #         2,
    #         "",
    #         "Mike"
    #       ],
    #       [
    #         3,
    #         3,
    #         "Japan",
    #         "Takashi"
    #       ],
    #       [
    #         4,
    #         4,
    #         "Japan",
    #         "Hanako"
    #       ]
    #     ]
    #   ]
    # ]

## 7.3.22.4. Parameters

`table`

> Specifies the name of table to delete the records.

`key`

> Specifies the key of record to delete. If you use the table with TABLE_NO_KEY, the key is just ignored. (Use `id` parameter in such a case)

`id`

> Specifies the id of record to delete. If you specify `id` parameter, you must not specify `key` parameter.

`filter`

> Specifies the expression of grn_expr to identify the record. If you specify `filter` parameter, you must not specify `key` and `id` parameter.

## 7.3.22.5. Return value

    [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.

## 7.3.22.6. See also

load