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.
如果我们没有为该列的所有子字段提供值,那么其余子字段将被填充为空值。
Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐