8.16.4. Modifying Composite Types

8.16.4. Modifying Composite Types
8.16.4.修改複合類型
Here are some examples of the proper syntax for inserting and updating composite columns. First, inserting or updating a whole column:
以下爲插入和更新複合類型的示例。首先,插入或更新整列:
 
INSERT INTO mytab (complex_col) VALUES((1.1,2.2));
UPDATE mytab SET complex_col = ROW(1.1,2.2) WHERE ...;
 
The first example omits ROW, the second uses it; we could have done it either way.
第一個示例省略了ROW,第二個示例使用了它;任一種方式均可。
 
We can update an individual subfield of a composite column:
也可以更新複合列的某一個子字段:
 
UPDATE mytab SET complex_col.r = (complex_col).r + 1 WHERE ...;
 
Notice here that we don't need to (and indeed cannot) put parentheses around the column name appearing just after SET, but we do need parentheses when referencing the same column in the expression to the right of the equal sign.
請注意,沒有必要(而且也不能)在SET之後的複合列名添加括號,但是必須爲等號右面的相同複合列名添加括號。
 
And we can specify subfields as targets for INSERT, too:
也可以在INSERT中指定子字段:
 
INSERT INTO mytab (complex_col.r, complex_col.i) VALUES(1.1, 2.2);
 
Had we not supplied values for all the subfields of the column, the remaining subfields would have been filled with null values.
如果我們沒有爲該列的所有子字段提供值,那麼其餘子字段將被填充爲空值。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章