1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
.. -*- rst -*-
.. highlightlang:: none
.. groonga-command
.. database: commands_delete
``delete``
==========
Summary
-------
``delete`` command deletes specified record of table.
.. _cascade-delete:
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.
Syntax
------
::
delete table [key [id [filter]]]
Usage
-----
Here are a schema definition and sample data to show usage.
.. groonga-command
.. table_create Entry TABLE_HASH_KEY UInt32
.. column_create Entry status --type ShortText
.. load --table Entry
.. [
.. {"_key": 1, "status": "OK"}
.. {"_key": 2, "status": "NG"}
.. ]
Delete the record from Entry table which has "2" as the key.
.. groonga-command
.. include:: ../../example/reference/commands/delete/status.log
.. delete Entry 2
.. select Entry
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.
.. groonga-command
.. include:: ../../example/reference/commands/delete/cascade.log
.. table_create Country TABLE_HASH_KEY ShortText
.. table_create Users TABLE_HASH_KEY UInt32
.. column_create Users name COLUMN_SCALAR ShortText
.. column_create Users country COLUMN_SCALAR Country
.. 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"}
.. ]
.. load --table Country
.. [
.. {"_key": "United States"}
.. {"_key": "Japan"}
.. ]
.. delete Country "United States"
.. select Country
.. select Users
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.
Return value
------------
::
[HEADER, SUCCEEDED_OR_NOT]
``HEADER``
See :doc:`/reference/command/output_format` about ``HEADER``.
``SUCCEEDED_OR_NOT``
If command succeeded, it returns true, otherwise it returns false on error.
See also
--------
:doc:`load`
|