Skip to content

Commit 59f3202

Browse files
committed
翻译 hstore.sgml
1 parent b2b6c88 commit 59f3202

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

postgresql/doc/src/sgml/hstore.sgml

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -620,21 +620,6 @@ ____________________________________________________________________________-->
620620
</tgroup>
621621
</table>
622622

623-
<note>
624-
<!--==========================orignal english content==========================
625-
<para>
626-
Prior to PostgreSQL 8.2, the containment operators <literal>@&gt;</literal>
627-
and <literal>&lt;@</literal> were called <literal>@</literal> and <literal>~</literal>,
628-
respectively. These names are still available, but are deprecated and will
629-
eventually be removed. Notice that the old names are reversed from the
630-
convention formerly followed by the core geometric data types!
631-
</para>
632-
____________________________________________________________________________-->
633-
<para>
634-
在 PostgreSQL 8.2 之前,包含操作符<literal>@&gt;</literal>和<literal>&lt;@</literal>分别被称为<literal>@</literal>和<literal>~</literal>。这些名称仍然可用,但是已经被弃用并且最终将被移除。注意,旧名称和原来核心几何数据类型所遵循的习惯是相反的!
635-
</para>
636-
</note>
637-
638623
<table id="hstore-func-table">
639624
<!--==========================orignal english content==========================
640625
<title><type>hstore</type> Functions</title>
@@ -1409,6 +1394,27 @@ ____________________________________________________________________________-->
14091394
</tbody>
14101395
</tgroup>
14111396
</table>
1397+
1398+
<para>
1399+
除了这个运算符和函数之外,<type>hstore</type>类型的值可以被索引,在这种情况下它们的行为就像关联数组。 <type>text</type>只允许该类型的单个下标。下标被解释为一个键,并检索或存储相应的值。例如:
1400+
<programlisting>
1401+
CREATE TABLE mytable (h hstore);
1402+
INSERT INTO mytable VALUES ('a=>b, c=>d');
1403+
SELECT h['a'] FROM mytable;
1404+
h
1405+
---
1406+
b
1407+
(1 row)
1408+
1409+
UPDATE mytable SET h['c'] = 'new';
1410+
SELECT h FROM mytable;
1411+
h
1412+
----------------------
1413+
"a"=>"b", "c"=>"new"
1414+
(1 row)
1415+
</programlisting>
1416+
如果索引是<literal>NULL</literal>,或者索引<type>hstore</type>中不存在键,则按索引获取<literal>NULL</literal>返回 。(所以下标检索<literal>-&gt;</literal>和算子区别不大。)如果下标是<literal>NULL</literal> ,则下标更新失败。否则,替换与该键对应的值<type>hstore</type>,如果该键不存在,则添加一个条目。
1417+
</para>
14121418
</sect2>
14131419

14141420
<sect2>
@@ -1516,7 +1522,15 @@ ____________________________________________________________________________-->
15161522
<para>
15171523
增加一个键,或者用一个新值更新一个现有的键:
15181524
<programlisting>
1525+
UPDATE tab SET h['c'] = '3';
1526+
</programlisting>
1527+
另一种方法:
1528+
<programlisting>
15191529
UPDATE tab SET h = h || hstore('c', '3');
1530+
</programlisting>
1531+
在单个操作中添加或修改多个键时,连接比下标更高效:
1532+
<programlisting>
1533+
UPDATE tab SET h = h || hstore(array['q', 'w'], array['11', '12']);
15201534
</programlisting>
15211535
</para>
15221536

@@ -1667,7 +1681,7 @@ ____________________________________________________________________________-->
16671681
<para>
16681682
使用一个表:
16691683
<programlisting>
1670-
SELECT (each(h)).key, (each(h)).value INTO stat FROM testhstore;
1684+
CREATE TABLE stat AS SELECT (each(h)).key, (each(h)).value FROM testhstore;
16711685
</programlisting>
16721686
</para>
16731687

@@ -1769,7 +1783,7 @@ ____________________________________________________________________________-->
17691783
<programlisting>
17701784
ALTER TABLE tablename ALTER hstorecol TYPE hstore USING hstorecol || '';
17711785
</programlisting>
1772-
<command>ALTER TABLE</command>方法要求表上的一个排他锁,但是不会导致表因为旧行版本而膨胀。
1786+
<command>ALTER TABLE</command>方法要求表上的一个<literal>ACCESS EXCLUSIVE</literal> 锁,但是不会导致表因为旧行版本而膨胀。
17731787
</para>
17741788

17751789
</sect2>

0 commit comments

Comments
 (0)