Sophie

Sophie

distrib > Fedora > 18 > x86_64 > media > updates > by-pkgid > e450e7f3d6075c4a54de19e68d38177f > files > 340

groonga-doc-3.0.5-1.fc18.x86_64.rpm


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>4.3. Various data types &mdash; groonga v3.0.5 documentation</title>
    
    <link rel="stylesheet" href="../_static/groonga.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '3.0.5',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="shortcut icon" href="../_static/favicon.ico"/>
    <link rel="top" title="groonga v3.0.5 documentation" href="../index.html" />
    <link rel="up" title="4. Tutorial" href="../tutorial.html" />
    <link rel="next" title="4.4. さまざまな検索条件の指定" href="search.html" />
    <link rel="prev" title="4.2. Remote access" href="network.html" /> 
  </head>
  <body>
<div class="header">
  <h1 class="title">
    <a id="top-link" href="../index.html">
      <span class="project">groonga</span>
      <span class="separator">-</span>
      <span class="description">An open-source fulltext search engine and column store.</span>
    </a>
  </h1>

  <div class="other-language-links">
    <ul>
      <li><a href="../../../ja/html/tutorial/data.html"><img src="../_static/jp.png" alt="日本語">日本語版はこちら</a></li>
    </ul>
  </div>
</div>
  

    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="search.html" title="4.4. さまざまな検索条件の指定"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="network.html" title="4.2. Remote access"
             accesskey="P">previous</a> |</li>
        <li><a href="../index.html">groonga v3.0.5 documentation</a> &raquo;</li>
          <li><a href="../tutorial.html" accesskey="U">4. Tutorial</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="various-data-types">
<h1>4.3. Various data types<a class="headerlink" href="#various-data-types" title="Permalink to this headline">¶</a></h1>
<p>Groonga is a full text search engine but also serves as a column-oriented data store. Groonga supports various data types, such as numeric types, string types, date and time type, longitude and latitude types, etc. This tutorial shows a list of data types and explains how to use them.</p>
<div class="section" id="overview">
<h2>4.3.1. Overview<a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h2>
<p>The basic data types of groonga are roughly divided into 5 groups --- boolean type, numeric types, string types, date/time type and longitude/latitude types. The numeric types are further divided according to whether integer or floating point number, signed or unsigned and the number of bits allocated to each integer. The string types are further divided according to the maximum length. The longitude/latitude types are further divided according to the geographic coordinate system. For more details, see <a class="reference internal" href="../reference/types.html"><em>データ型</em></a>.</p>
<p>In addition, groonga supports reference types and vector types. Reference types are designed for accessing other tables. Vector types are designed for storing a variable number of values in one element.</p>
<p>First, let's create a table for this tutorial.</p>
<p>Execution example:</p>
<div class="highlight-none"><div class="highlight"><pre>table_create --name ToyBox --flags TABLE_HASH_KEY --key_type ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
</pre></div>
</div>
</div>
<div class="section" id="boolean-type">
<h2>4.3.2. Boolean type<a class="headerlink" href="#boolean-type" title="Permalink to this headline">¶</a></h2>
<p>The boolean type is used to store true or false. To create a boolean type column, specify Bool to the <cite>type</cite> parameter of <a class="reference internal" href="../reference/commands/column_create.html"><em>column_create</em></a> command. The default value of the boolean type is false.</p>
<p>The following example creates a boolean type column and adds three records. Note that the third record has the default value because no value is specified.</p>
<p>Execution example:</p>
<div class="highlight-none"><div class="highlight"><pre>column_create --table ToyBox --name is_animal --type Bool
# [[0, 1337566253.89858, 0.000355720520019531], true]
load --table ToyBox
[
{&quot;_key&quot;:&quot;Monkey&quot;,&quot;is_animal&quot;:true}
{&quot;_key&quot;:&quot;Flower&quot;,&quot;is_animal&quot;:false}
{&quot;_key&quot;:&quot;Block&quot;}
]
# [[0, 1337566253.89858, 0.000355720520019531], 3]
select --table ToyBox --output_columns _key,is_animal
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         3
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;is_animal&quot;,
#           &quot;Bool&quot;
#         ]
#       ],
#       [
#         &quot;Monkey&quot;,
#         true
#       ],
#       [
#         &quot;Flower&quot;,
#         false
#       ],
#       [
#         &quot;Block&quot;,
#         false
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
</div>
<div class="section" id="numeric-types">
<h2>4.3.3. Numeric types<a class="headerlink" href="#numeric-types" title="Permalink to this headline">¶</a></h2>
<p>The numeric types are divided into integer types and a floating point number type. The integer types are further divided into the signed integer types and unsigned integer types. In addition, you can choose the number of bits allocated to each integer. For more details, see <a class="reference internal" href="../reference/types.html"><em>データ型</em></a>. The default value of the numeric types is 0.</p>
<p>The following example creates an Int8 column and a Float column, and then updates existing records. The <a class="reference internal" href="../reference/commands/load.html"><em>load</em></a> command updates the weight column as expected. On the other hand, the price column values are different from the specified values because 15.9 is not an integer and 200 is too large. 15.9 is converted to 15 by removing the fractional part. 200 causes an overflow and the result becomes -56. Note that the result of an overflow/underflow is undefined.</p>
<p>Execution example:</p>
<div class="highlight-none"><div class="highlight"><pre>column_create --table ToyBox --name price --type Int8
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create --table ToyBox --name weight --type Float
# [[0, 1337566253.89858, 0.000355720520019531], true]
load --table ToyBox
[
{&quot;_key&quot;:&quot;Monkey&quot;,&quot;price&quot;:15.9}
{&quot;_key&quot;:&quot;Flower&quot;,&quot;price&quot;:200,&quot;weight&quot;:0.13}
{&quot;_key&quot;:&quot;Block&quot;,&quot;weight&quot;:25.7}
]
# [[0, 1337566253.89858, 0.000355720520019531], 3]
select --table ToyBox --output_columns _key,price,weight
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         3
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;price&quot;,
#           &quot;Int8&quot;
#         ],
#         [
#           &quot;weight&quot;,
#           &quot;Float&quot;
#         ]
#       ],
#       [
#         &quot;Monkey&quot;,
#         15,
#         0.0
#       ],
#       [
#         &quot;Flower&quot;,
#         -56,
#         0.13
#       ],
#       [
#         &quot;Block&quot;,
#         0,
#         25.7
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
</div>
<div class="section" id="string-types">
<h2>4.3.4. String types<a class="headerlink" href="#string-types" title="Permalink to this headline">¶</a></h2>
<p>The string types are divided according to the maximum length. For more details, see <a class="reference internal" href="../reference/types.html"><em>データ型</em></a>. The default value is the zero-length string.</p>
<p>The following example creates a ShortText column and updates existing records. The third record has the default value because not updated.</p>
<p>Execution example:</p>
<div class="highlight-none"><div class="highlight"><pre>column_create --table ToyBox --name name --type ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
load --table ToyBox
[
{&quot;_key&quot;:&quot;Monkey&quot;,&quot;name&quot;:&quot;Grease&quot;}
{&quot;_key&quot;:&quot;Flower&quot;,&quot;name&quot;:&quot;Rose&quot;}
]
# [[0, 1337566253.89858, 0.000355720520019531], 2]
select --table ToyBox --output_columns _key,name
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         3
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;name&quot;,
#           &quot;ShortText&quot;
#         ]
#       ],
#       [
#         &quot;Monkey&quot;,
#         &quot;Grease&quot;
#       ],
#       [
#         &quot;Flower&quot;,
#         &quot;Rose&quot;
#       ],
#       [
#         &quot;Block&quot;,
#         &quot;&quot;
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
</div>
<div class="section" id="date-and-time-type">
<h2>4.3.5. Date and time type<a class="headerlink" href="#date-and-time-type" title="Permalink to this headline">¶</a></h2>
<p>The date and time type of groonga is Time. Actually, a Time column stores a date and time as the number of microseconds since the Epoch, 1970-01-01 00:00:00. A Time value can represent a date and time before the Epoch because the actual data type is a signed integer. Note that <a class="reference internal" href="../reference/commands/load.html"><em>load</em></a> and <a class="reference internal" href="../reference/commands/select.html"><em>select</em></a> commands use a decimal number to represent a data and time in seconds. The default value is 0.0, which means the Epoch.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Groonga internally holds the value of Epoch as pair of integer. The first integer represents the value of seconds, on the other hand, the second integer represents the value of micro seconds.
So, groonga shows the value of Epoch as floating point. Integral part means the value of seconds, fraction part means the value of micro seconds.</p>
</div>
<p>The following example creates a Time column and updates existing records. The first record has the default value because not updated.</p>
<p>Execution example:</p>
<div class="highlight-none"><div class="highlight"><pre>column_create --table ToyBox --name time --type Time
# [[0, 1337566253.89858, 0.000355720520019531], true]
load --table ToyBox
[
{&quot;_key&quot;:&quot;Flower&quot;,&quot;time&quot;:1234567890.1234569999}
{&quot;_key&quot;:&quot;Block&quot;,&quot;time&quot;:-1234567890}
]
# [[0, 1337566253.89858, 0.000355720520019531], 2]
select --table ToyBox --output_columns _key,time
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         3
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;time&quot;,
#           &quot;Time&quot;
#         ]
#       ],
#       [
#         &quot;Monkey&quot;,
#         0.0
#       ],
#       [
#         &quot;Flower&quot;,
#         1234567890.12346
#       ],
#       [
#         &quot;Block&quot;,
#         -1234567890.0
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
</div>
<div class="section" id="longitude-and-latitude-types">
<h2>4.3.6. Longitude and latitude types<a class="headerlink" href="#longitude-and-latitude-types" title="Permalink to this headline">¶</a></h2>
<p>The longitude and latitude types are divided according to the geographic coordinate system. For more details, see <a class="reference internal" href="../reference/types.html"><em>データ型</em></a>. To represent a longitude and latitude, groonga uses a string formatted as follows:</p>
<ul class="simple">
<li>&quot;longitude x latitude&quot; in milliseconds (e.g.: &quot;128452975x503157902&quot;)</li>
<li>&quot;longitude x latitude&quot; in degrees (e.g.: &quot;35.6813819x139.7660839&quot;)</li>
</ul>
<p>A number with/without a decimal point represents a longitude or latitude in milliseconds/degrees respectively. Note that a combination of a number with a decimal point and a number without a decimal point (e.g. 35.1x139) must not be used. A comma (',') is also available as a delimiter. The default value is &quot;0x0&quot;.</p>
<p>The following example creates a WGS84GeoPoint column and updates existing records. The second record has the default value because not updated.</p>
<p>Execution example:</p>
<div class="highlight-none"><div class="highlight"><pre>column_create --table ToyBox --name location --type WGS84GeoPoint
# [[0, 1337566253.89858, 0.000355720520019531], true]
load --table ToyBox
[
{&quot;_key&quot;:&quot;Monkey&quot;,&quot;location&quot;:&quot;128452975x503157902&quot;}
{&quot;_key&quot;:&quot;Block&quot;,&quot;location&quot;:&quot;35.6813819x139.7660839&quot;}
]
# [[0, 1337566253.89858, 0.000355720520019531], 2]
select --table ToyBox --output_columns _key,location
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         3
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;location&quot;,
#           &quot;WGS84GeoPoint&quot;
#         ]
#       ],
#       [
#         &quot;Monkey&quot;,
#         &quot;128452975x503157902&quot;
#       ],
#       [
#         &quot;Flower&quot;,
#         &quot;0x0&quot;
#       ],
#       [
#         &quot;Block&quot;,
#         &quot;128452975x503157902&quot;
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
</div>
<div class="section" id="reference-types">
<h2>4.3.7. Reference types<a class="headerlink" href="#reference-types" title="Permalink to this headline">¶</a></h2>
<p>Groonga supports a reference column, which stores references to records in its associated table. In practice, a reference column stores the IDs of the referred records in the associated table and enables access to those records.</p>
<p>You can specify a column in the associated table to the <cite>output_columns</cite> parameter of a <a class="reference internal" href="../reference/commands/select.html"><em>select</em></a> command. The format is &quot;Src.Dest&quot; where Src is the name of the reference column and Dest is the name of the target column. If only the reference column is specified, it is handled as &quot;Src._key&quot;. Note that if a reference does not point to a valid record, a <a class="reference internal" href="../reference/commands/select.html"><em>select</em></a> command outputs the default value of the target column.</p>
<p>The following example adds a reference column to the Site table that was created in the previous tutorial. The new column, named link, is designed for storing links among records in the Site table.</p>
<p>Execution example:</p>
<div class="highlight-none"><div class="highlight"><pre>column_create --table Site --name link --type Site
# [[0, 1337566253.89858, 0.000355720520019531], true]
load --table Site
[{&quot;_key&quot;:&quot;http://example.org/&quot;,&quot;link&quot;:&quot;http://example.net/&quot;}]
select --table Site --output_columns _key,title,link._key,link.title --query title:@this
# [[0, 1337566253.89858, 0.000355720520019531], 1]
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         1
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;title&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;link._key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;link.title&quot;,
#           &quot;ShortText&quot;
#         ]
#       ],
#       [
#         &quot;http://example.org/&quot;,
#         &quot;This is test record 1!&quot;,
#         &quot;http://example.net/&quot;,
#         &quot;test record 2.&quot;
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>The <cite>type</cite> parameter of the <a class="reference internal" href="../reference/commands/column_create.html"><em>column_create</em></a> command specifies the table to be associated with the reference column. In this example, the reference column is associated with the own table. Then, the <a class="reference internal" href="../reference/commands/load.html"><em>load</em></a> command registers a link from &quot;<a class="reference external" href="http://example.org">http://example.org</a>&quot; to &quot;<a class="reference external" href="http://example.net">http://example.net</a>&quot;. Note that a reference column requires the primary key, not the ID, of the record to be referred to. After that, the link is confirmed by the <a class="reference internal" href="../reference/commands/select.html"><em>select</em></a> command. In this case, the primary key and the title of the referred record are output because link._key and link.title are specified to the <cite>output_columns</cite> parameter.</p>
</div>
<div class="section" id="vector-types">
<h2>4.3.8. Vector types<a class="headerlink" href="#vector-types" title="Permalink to this headline">¶</a></h2>
<p>Groonga supports a vector column, in which each element can store a variable number of values. To create a vector column, specify the COLUMN_VECTOR flag to the <cite>flags</cite> parameter of a <a class="reference internal" href="../reference/commands/column_create.html"><em>column_create</em></a> command. A vector column is useful to represent a many-to-many relationship.</p>
<p>The previous example used a regular column, so each record could have at most one link. Obviously, the specification is insufficient because a site usually has more than one links. To solve this problem, the following example uses a vector column.</p>
<p>Execution example:</p>
<div class="highlight-none"><div class="highlight"><pre>column_create --table Site --name links --flags COLUMN_VECTOR --type Site
# [[0, 1337566253.89858, 0.000355720520019531], true]
load --table Site
[{&quot;_key&quot;:&quot;http://example.org/&quot;,&quot;links&quot;:[&quot;http://example.net/&quot;,&quot;http://example.org/&quot;,&quot;http://example.com/&quot;]}]
select --table Site --output_columns _key,title,links._key,links.title --query title:@this
# [[0, 1337566253.89858, 0.000355720520019531], 1]
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         1
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;title&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;links._key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;links.title&quot;,
#           &quot;ShortText&quot;
#         ]
#       ],
#       [
#         &quot;http://example.org/&quot;,
#         &quot;This is test record 1!&quot;,
#         [
#           &quot;http://example.net/&quot;,
#           &quot;http://example.org/&quot;,
#           &quot;http://example.com/&quot;
#         ],
#         [
#           &quot;test record 2.&quot;,
#           &quot;This is test record 1!&quot;,
#           &quot;test test record three.&quot;
#         ]
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>The only difference at the first step is the <cite>flags</cite> parameter that specifies to create a vector column. The <cite>type</cite> parameter of the <a class="reference internal" href="../reference/commands/column_create.html"><em>column_create</em></a> command is the same as in the previous example. Then, the <a class="reference internal" href="../reference/commands/load.html"><em>load</em></a> command registers three links from &quot;<a class="reference external" href="http://example.org/">http://example.org/</a>&quot; to &quot;<a class="reference external" href="http://example.net/">http://example.net/</a>&quot;, &quot;<a class="reference external" href="http://example.org/">http://example.org/</a>&quot; and &quot;<a class="reference external" href="http://example.com/">http://example.com/</a>&quot;. After that, the links are confirmed by the <a class="reference internal" href="../reference/commands/select.html"><em>select</em></a> command. In this case, the primary keys and the titles are output as arrays because links._key and links.title are specified to the <cite>output_columns</cite> parameter.</p>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">4.3. Various data types</a><ul>
<li><a class="reference internal" href="#overview">4.3.1. Overview</a></li>
<li><a class="reference internal" href="#boolean-type">4.3.2. Boolean type</a></li>
<li><a class="reference internal" href="#numeric-types">4.3.3. Numeric types</a></li>
<li><a class="reference internal" href="#string-types">4.3.4. String types</a></li>
<li><a class="reference internal" href="#date-and-time-type">4.3.5. Date and time type</a></li>
<li><a class="reference internal" href="#longitude-and-latitude-types">4.3.6. Longitude and latitude types</a></li>
<li><a class="reference internal" href="#reference-types">4.3.7. Reference types</a></li>
<li><a class="reference internal" href="#vector-types">4.3.8. Vector types</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="network.html"
                        title="previous chapter">4.2. Remote access</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="search.html"
                        title="next chapter">4.4. さまざまな検索条件の指定</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../_sources/tutorial/data.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="search.html" title="4.4. さまざまな検索条件の指定"
             >next</a> |</li>
        <li class="right" >
          <a href="network.html" title="4.2. Remote access"
             >previous</a> |</li>
        <li><a href="../index.html">groonga v3.0.5 documentation</a> &raquo;</li>
          <li><a href="../tutorial.html" >4. Tutorial</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2009-2013, Brazil, Inc.
    </div>
  </body>
</html>