File: load.rst

package info (click to toggle)
groonga 9.0.0-1%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 101,496 kB
  • sloc: ansic: 608,707; ruby: 35,042; xml: 23,643; cpp: 10,319; sh: 7,453; yacc: 5,968; python: 3,033; makefile: 2,609; perl: 133
file content (269 lines) | stat: -rw-r--r-- 5,974 bytes parent folder | download
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
.. -*- rst -*-

.. highlightlang:: none

.. groonga-command
.. database: commands_load

``load``
========

Summary
-------


``load`` loads data as records in the current database and updates values of each columns.

Syntax
------

The required parameters are only ``values`` and ``table``. Other
parameters are optional::

  load values
       table
       [columns=null]
       [ifexists=null]
       [input_type=json]
       [each=null]
       [output_ids=no]
       [output_errors=no]
       [lock_table=no]

This command is a special command. Other commands need to pass all
parameters to one line but this command can accept ``values`` as
followed data.

If you use command line style, you can pass ``values`` like the
following::

  load --table Bookmarks
  [
  {"_key": "http://groonga.org/", "title": "Groonga"},
  {"_key": "http://mroonga.org/", "title": "Mroonga"}
  ]

``[...]`` is value of ``values``.

If you use HTTP style, you can pass ``values`` as body::

  % curl \
      --request POST \
      --header "Content-Type: application/json" \
      --data-raw '[{"_key": "http://groonga.org/"}]' \
      http://localhost:10041/d/load?table=Bookmarks"


Usage
-----

Here are schema definitions to show usage:

.. groonga-command
.. include:: ../../example/reference/commands/load/usage_setup.log
.. table_create Entries TABLE_HASH_KEY ShortText
.. column_create Entries content COLUMN_SCALAR Text

Here is an example to add records to ``Entries`` table by parameter:

.. groonga-command
.. include:: ../../example/reference/commands/load/usage_parameter.log
.. load \
..   --table Entries \
..   --values "[{\"_key\":\"Groonga\",\"content\":\"It's very fast!!\"}]"

Here is an example to add records to ``Entries`` table from standard input:

.. groonga-command
.. include:: ../../example/reference/commands/load/usage_standard_input.log
.. load --table Entries
.. [
.. {"_key": "Groonga", "content": "It's very fast!!"}
.. ]

Here is an example to lock table while updating columns:

.. groonga-command
.. include:: ../../example/reference/commands/load/usage_lock_table.log
.. load --table Entries --lock_table yes
.. [
.. {"_key": "Groonga", "content": "It's very fast!!"}
.. ]

Parameters
----------

This section describes all parameters. Parameters are categorized.

Required parameters
^^^^^^^^^^^^^^^^^^^

There are some required parameters.

.. _load-values:

``values``
""""""""""

Specifies values to be loaded.

Values should satisfy ``input_type`` format. If you specify ``json``
as ``input_type``, you can choose a format from below:

Bracket style::

  [
  [COLUMN_NAME1, COLUMN_NAME2, ...],
  [VALUE1, VALUE2, ...],
  [VALUE1, VALUE2, ...],
  ...
  ]

Brace style::

  [
  {"COLUMN_NAME1": VALUE1, "COLUMN_NAME2": VALUE2, ...},
  {"COLUMN_NAME1": VALUE1, "COLUMN_NAME2": VALUE2, ...},
  ...
  ]

``[COLUMN_NAME1, COLUMN_NAME2, ...]`` in bracket style is effective
only when :ref:`load-columns` parameter isn't specified.

When a target table contains primary key, you must specify ``_key``
column (pseudo column associated primary key) as the one of
``COLUMN_NAME``.

If ``values`` isn't specified any values, they are read from the
standard input in command line style or body in HTTP style.

.. _load-table:

``table``
"""""""""

Specifies a table name you want to add records.

Optional parameters
^^^^^^^^^^^^^^^^^^^

There are some optional parameters.

.. _load-columns:

``columns``
"""""""""""

Specifies column names in added records with comma separations.

.. _load-ifexists:

``ifexists``
""""""""""""

Specifies executed expression in
:doc:`/reference/grn_expr/script_syntax` when the same primary key as
added records already exists in your table.

If ``ifexists`` specifies expression and its value is ``true``, values
in other (all columns excluding ``_key`` column) columns is updated.

.. _load-input-type:

``input_type``
""""""""""""""

Specifies an input format for ``values``. It supports only ``json``
for now. It means format of ``values`` is JSON.

The default value is ``json``.

.. _load-each:

``each``
""""""""

TODO

.. _load-output-ids:

``output_ids``
""""""""""""""

TODO

.. _load-output-errors:

``output_errors``
"""""""""""""""""

TODO

.. _load-lock-table:

``lock_table``
""""""""""""""

.. versionadded:: 8.0.6

Specifies whether locking table while updating columns.

The default is ``no``.

If you may run destructive commands such as ``load``, ``delete`` and
so on concurrently, it may break database. For example, if you're
updating a record by ``load`` and deleting the updating record by
``delete``, the ``load`` may refer the delete record.

You can guard the update conflict by locking the target table but it
reduces load performance.

If you specify ``yes`` to this parameter, you can lock the target
table while updating columns. Here is the update sequence of each
record:

  1. Lock the target table
  2. Add or refer a record to the target table
  3. Unlock the target table
  4. Lock the target table when ``lock_table`` is ``yes``
  5. Update columns of the target record
  6. Unlock the target table when ``lock_table`` is ``yes``

Return value
------------

The command returns a response with the following format::

  [THE_NUMBER_OF_LOADED_RECORDS]

The command returns a response with the following format with
:doc:`/reference/command/command_version` 3 or later::

  {
    "n_loaded_records": THE_NUMBER_OF_LOADED_RECORDS,
    "loaded_ids": [
      LOADED_RECORD'S_ID1,
      LOADED_RECORD'S_ID2,
      ...
    ],
    "errors": [
      {
        "return_code": RETURN_CODE_FOR_1ST_RECORD,
        "message": MESSAGE_FOR_1ST_RECORD
      },
      {
        "return_code": RETURN_CODE_FOR_2ND_RECORD,
        "message": MESSAGE_FOR_2ND_RECORD
      },
      ...
    ]
  }

``loaded_ids`` is only included when :ref:`load-output-ids` is ``yes``.

``errors`` is only included when :ref:`load-output-errors` is ``yes``.

See also
--------

  * :doc:`/reference/grn_expr/script_syntax`