@@ -620,21 +620,6 @@ ____________________________________________________________________________-->
620
620
</tgroup>
621
621
</table>
622
622
623
- <note>
624
- <!--==========================orignal english content==========================
625
- <para>
626
- Prior to PostgreSQL 8.2, the containment operators <literal>@></literal>
627
- and <literal><@</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>@></literal>和<literal><@</literal>分别被称为<literal>@</literal>和<literal>~</literal>。这些名称仍然可用,但是已经被弃用并且最终将被移除。注意,旧名称和原来核心几何数据类型所遵循的习惯是相反的!
635
- </para>
636
- </note>
637
-
638
623
<table id="hstore-func-table">
639
624
<!--==========================orignal english content==========================
640
625
<title><type>hstore</type> Functions</title>
@@ -1409,6 +1394,27 @@ ____________________________________________________________________________-->
1409
1394
</tbody>
1410
1395
</tgroup>
1411
1396
</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>-></literal>和算子区别不大。)如果下标是<literal>NULL</literal> ,则下标更新失败。否则,替换与该键对应的值<type>hstore</type>,如果该键不存在,则添加一个条目。
1417
+ </para>
1412
1418
</sect2>
1413
1419
1414
1420
<sect2>
@@ -1516,7 +1522,15 @@ ____________________________________________________________________________-->
1516
1522
<para>
1517
1523
增加一个键,或者用一个新值更新一个现有的键:
1518
1524
<programlisting>
1525
+ UPDATE tab SET h['c'] = '3';
1526
+ </programlisting>
1527
+ 另一种方法:
1528
+ <programlisting>
1519
1529
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']);
1520
1534
</programlisting>
1521
1535
</para>
1522
1536
@@ -1667,7 +1681,7 @@ ____________________________________________________________________________-->
1667
1681
<para>
1668
1682
使用一个表:
1669
1683
<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;
1671
1685
</programlisting>
1672
1686
</para>
1673
1687
@@ -1769,7 +1783,7 @@ ____________________________________________________________________________-->
1769
1783
<programlisting>
1770
1784
ALTER TABLE tablename ALTER hstorecol TYPE hstore USING hstorecol || '';
1771
1785
</programlisting>
1772
- <command>ALTER TABLE</command>方法要求表上的一个排他锁 ,但是不会导致表因为旧行版本而膨胀。
1786
+ <command>ALTER TABLE</command>方法要求表上的一个<literal>ACCESS EXCLUSIVE</literal> 锁 ,但是不会导致表因为旧行版本而膨胀。
1773
1787
</para>
1774
1788
1775
1789
</sect2>
0 commit comments