Debian Codegraph @

doc/source/reference/commands/delete.rst

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