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 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
|
.. -*- rst -*-
.. highlightlang:: none
.. groonga-command
.. database: commands_copy
``column_copy``
===============
Summary
-------
.. versionadded:: 5.0.7
``column_copy`` copies all column values to other column.
You can implement the following features with this command:
* Changing column configuration
* Changing table configuration
You can change column configuration by the following steps:
1. Create a new column with new configuration
2. Copy all values from the current column to the new column
3. Remove the current column
4. Rename the new column to the current column
You can change table configuration by the following steps:
1. Create a new table with new configuration
2. Create all same columns to the new table
3. Copy all column values from the current table to the new table
4. Remove the current table
5. Rename the new table to the current table
Concrete examples are showed later.
You can't copy column values from a ``TABLE_NO_KEY`` table to another
table. And you can't copy column values to a ``TABLE_NO_KEY`` table
from another table. Because Groonga can't map records without record
key.
You can copy column values from a ``TABLE_NO_KEY`` table to the same
``TABLE_NO_KEY`` table.
You can copy column values from a ``TABLE_HASH_KEY`` /
``TABLE_PAT_KEY`` / ``TABLE_DAT_KEY`` table to the same or another
``TABLE_HASH_KEY`` / ``TABLE_PAT_KEY`` / ``TABLE_DAT_KEY`` table.
Syntax
------
This command takes four parameters.
All parameters are required::
column_copy from_table
from_name
to_table
to_name
Usage
-----
Here are use cases of this command:
* Changing column configuration
* Changing table configuration
How to change column configuration
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You can change column value type. For example, you can change
``UInt32`` column value to ``ShortText`` column value.
You can change column type. For example, you can change
``COLUMN_SCALAR`` column to ``COLUMN_VECTOR`` column.
You can move a column to other table. For example, you can move
``high_score`` column to ``Users`` table from ``Players`` table.
Here are basic steps to change column configuration:
1. Create a new column with new configuration
2. Copy all values from the current column to the new column
3. Remove the current column
4. Rename the new column to the current column
Here is an example to change column value type to ``Int32`` from
``ShortText``.
Here are schema and data:
.. groonga-command
.. include:: ../../example/reference/commands/column_copy/change_column_value_type_setup.log
.. table_create Logs TABLE_HASH_KEY ShortText
.. column_create Logs serial COLUMN_SCALAR Int32
.. load --table Logs
.. [
.. {"_key": "log1", "serial": 1}
.. ]
The following commands change ``Logs.serial`` column value type to
``ShortText`` from ``Int32``:
.. groonga-command
.. include:: ../../example/reference/commands/column_copy/change_column_value_type.log
.. column_create Logs new_serial COLUMN_SCALAR ShortText
.. column_copy Logs serial Logs new_serial
.. column_remove Logs serial
.. column_rename Logs new_serial serial
.. select Logs
You can find ``Logs.serial`` stores ``ShortText`` value from the
response of ``select``.
Here is an example to change column type to ``COLUMN_VECTOR`` from
``COLUMN_SCALAR``.
Here are schema and data:
.. groonga-command
.. include:: ../../example/reference/commands/column_copy/change_column_type_setup.log
.. table_create Entries TABLE_HASH_KEY ShortText
.. column_create Entries tag COLUMN_SCALAR ShortText
.. load --table Entries
.. [
.. {"_key": "entry1", "tag": "Groonga"}
.. ]
The following commands change ``Entries.tag`` column to
``COLUMN_VECTOR`` from ``COLUMN_SCALAR``:
.. groonga-command
.. include:: ../../example/reference/commands/column_copy/change_column_type.log
.. column_create Entries new_tag COLUMN_VECTOR ShortText
.. column_copy Entries tag Entries new_tag
.. column_remove Entries tag
.. column_rename Entries new_tag tag
.. select Entries
You can find ``Entries.tag`` stores ``COLUMN_VECTOR`` value from the
response of ``select``.
Here is an example to move ``high_score`` column to ``Users`` table
from ``Players`` table.
Here are schema and data:
.. groonga-command
.. include:: ../../example/reference/commands/column_copy/move_column_setup.log
.. table_create Players TABLE_HASH_KEY ShortText
.. column_create Players high_score COLUMN_SCALAR Int32
.. load --table Players
.. [
.. {"_key": "player1", "high_score": 100}
.. ]
The following commands move ``high_score`` column to ``Users`` table
from ``Players`` table:
.. groonga-command
.. include:: ../../example/reference/commands/column_copy/move_column.log
.. table_create Users TABLE_HASH_KEY ShortText
.. column_create Users high_score COLUMN_SCALAR Int32
.. column_copy Players high_score Users high_score
.. column_remove Players high_score
.. select Users
You can find ``Users.high_score`` is moved from ``Players.high_score``
from the response of ``select``.
How to change table configuration
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You can change table key type. For example, you can change
key type to ``ShortText`` from ``Int32``.
You can change table type. For example, you can change
``TABLE_HASH_KEY`` table to ``TABLE_PAT_KEY`` table.
You can also change other options such as default tokenizer and
normalizer. For example, you can change default tokenizer to
``TokenBigramSplitSymbolAlphaDigit`` from ``TokenBigrm``.
.. note::
You can't change ``TABLE_NO_KEY`` table. Because ``TABLE_NO_KEY``
doesn't have record key. Groonga can't identify copy destination
record without record key.
Here are basic steps to change table configuration:
1. Create a new table with new configuration
2. Create all same columns to the new table
3. Copy all column values from the current table to the new table
4. Remove the current table
5. Rename the new table to the current table
Here is an example to change table key type to ``ShortText`` from
``Int32``.
Here are schema and data:
.. groonga-command
.. include:: ../../example/reference/commands/column_copy/change_table_key_type_setup.log
.. table_create IDs TABLE_HASH_KEY Int32
.. column_create IDs label COLUMN_SCALAR ShortText
.. column_create IDs used COLUMN_SCALAR Bool
.. load --table IDs
.. [
.. {"_key": 100, "label": "ID 100", used: true}
.. ]
The following commands change ``IDs`` table key type to ``ShortText``
from ``Int32``:
.. groonga-command
.. include:: ../../example/reference/commands/column_copy/change_table_key_type.log
.. table_create NewIDs TABLE_HASH_KEY Int32
.. column_create NewIDs label COLUMN_SCALAR ShortText
.. column_create NewIDs used COLUMN_SCALAR Bool
.. column_copy IDs label NewIDs label
.. column_copy IDs used NewIDs used
.. table_remove IDs
.. table_rename NewIDs IDs
.. select IDs
You can find ``IDs`` stores ``ShortText`` key from the response of
``select``.
Here is an example to change table type to ``TABLE_PAT_KEY`` from
``TABLE_HASH_KEY``.
Here are schema and data:
.. groonga-command
.. include:: ../../example/reference/commands/column_copy/change_table_type_setup.log
.. table_create Names TABLE_HASH_KEY ShortText
.. column_create Names used COLUMN_SCALAR Bool
.. load --table Names
.. [
.. {"_key": "alice", "used": false}
.. ]
The following commands change ``Names`` table to ``TABLE_PAT_KEY``
from ``TABLE_HASH_KEY``:
.. groonga-command
.. include:: ../../example/reference/commands/column_copy/change_table_type.log
.. table_create NewNames TABLE_PAT_KEY ShortText
.. column_create NewNames used COLUMN_SCALAR Bool
.. column_copy Names used NewNames used
.. table_remove Names
.. table_rename NewNames Names
.. select Names --filter '_key @^ "ali"'
You can find ``Names`` is a ``TABLE_PAT_KEY`` because ``select`` can
use :ref:`script-syntax-prefix-search-operator`. You can't use
:ref:`script-syntax-prefix-search-operator` with ``TABLE_HASH_KEY``.
Parameters
----------
This section describes parameters.
Required parameters
^^^^^^^^^^^^^^^^^^^
All parameters are required.
.. _column-copy-from-table:
``from_table``
""""""""""""""
Specifies the table name of source column.
You can specify any table including ``TABLE_NO_KEY`` table.
If you specify ``TABLE_NO_KEY`` table, :ref:`column-copy-to-table`
must be the same table.
Here is an example to use ``from_table``.
Here are schema and data:
.. groonga-command
.. include:: ../../example/reference/commands/column_copy/from_table_setup.log
.. table_create FromTable TABLE_HASH_KEY ShortText
.. column_create FromTable from_column COLUMN_SCALAR ShortText
.. column_create FromTable to_column COLUMN_SCALAR ShortText
.. load --table FromTable
.. [
.. {"_key": "key1", "from_column": "value1"}
.. ]
.. select FromTable --output_columns _key,from_column,to_column
You can copy all values to ``to_column`` from ``from_column``:
.. groonga-command
.. include:: ../../example/reference/commands/column_copy/from_table.log
.. column_copy FromTable from_column FromTable to_column
.. select FromTable --output_columns _key,from_column,to_column
.. _column-copy-from-name:
``from_name``
"""""""""""""
Specifies the column name to be copied values.
See :ref:`column-copy-from-table` for example.
.. _column-copy-to-table:
``to_table``
""""""""""""
Specifies the table name of destination column.
You can specify the same table name as :ref:`column-copy-from-table`
when you want to copy column values in the same table.
You can't specify ``TABLE_NO_KEY`` table to ``to_table`` because
Groonga can't identify destination records without record key.
There is one exception. If you specify the same name as ``from_table``
to ``to_table``, you can use ``TABLE_NO_KEY`` table as
``to_table``. Because Groonga can identify destination records when
source table and destination table is the same table.
Here is an example to use ``to_table``.
Here are schema and data:
.. groonga-command
.. include:: ../../example/reference/commands/column_copy/to_table_setup.log
.. table_create Table TABLE_HASH_KEY ShortText
.. column_create Table column COLUMN_SCALAR ShortText
.. table_create ToTable TABLE_HASH_KEY ShortText
.. column_create ToTable to_column COLUMN_SCALAR ShortText
.. load --table Table
.. [
.. {"_key": "key1", "column": "value1"}
.. ]
You can copy all values to ``ToTable.to_column`` from
``Table.column``:
.. groonga-command
.. include:: ../../example/reference/commands/column_copy/to_table.log
.. column_copy Table column ToTable to_column
.. select ToTable --output_columns _key,to_column
.. _column-copy-to-name:
``to_name``
"""""""""""
Specifies the destination column name.
See :ref:`column-copy-to-table` for example.
Optional parameters
^^^^^^^^^^^^^^^^^^^
There is no optional parameter.
Return value
------------
The command returns ``true`` as body on success such as::
[HEADER, true]
If the command fails, error details are in ``HEADER``.
See :doc:`/reference/command/output_format` for ``HEADER``.
|