RefLib

Reference library for AI

Back

postgresql_16:3.5.16.4 Modifying Composite Types

PostgreSQL 16 > The SQL Language > Data Types > Composite Types > Modifying Composite Types

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.

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.

And we can specify subfields as targets for INSERT, too: 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.

Back