Composite Data Types

composite type represents the structure of a row or record; it is essentially just a list of field names and their data types.

YugabyteDB allows composite types to be used in many of the same ways that simple types can be used. For example, a column of a table can be declared to be of a composite type.

Example:

				
					
yugabyte=# CREATE TYPE full_name_type AS (
yugabyte(#   first TEXT,
yugabyte(#   middle TEXT,
yugabyte(#   last TEXT
yugabyte(# );
CREATE TYPE

yugabyte=# CREATE TABLE presidents (full_name full_name_type);
CREATE TABLE

yugabyte=# INSERT INTO presidents VALUES (ROW('Dwight', 'David', 'Eisenhower'));
INSERT 0 1

yugabyte=# INSERT INTO presidents VALUES (ROW('Franklin', 'Delano', 'Roosevelt'));
INSERT 0 1

yugabyte=# SELECT full_name FROM presidents;
          full_name
-----------------------------
 (Dwight,David,Eisenhower)
 (Franklin,Delano,Roosevelt)
(2 rows)

yugabyte=# SELECT (full_name).first, (full_name).middle, (full_name).last FROM presidents;
  first   | middle |    last
----------+--------+------------
 Dwight   | David  | Eisenhower
 Franklin | Delano | Roosevelt
(2 rows)
				
			

Have Fun!