Skip to main content

Define a struct type

Syntax:STRUCT< > Struct types are declared using the angle brackets (< and >).
Starting from v2.7.0, RisingWave supports empty struct types, allowing you to define a struct with zero fields, serving as a placeholder for potential future additions of fields. To declare an empty struct, include a space between the angle brackets < >. This prevents conflicts with the <> (not equal) operator during SQL parsing.

Examples

The statement below creates a table x that contains struct a, which contains two nested columns (b and c) that are both integers.
The statement below creates a table y that contains struct a, which contains another struct c.
Below is a real world example.
You can also use the struct type to parse a string that contains data in JSON format into its proper format. For instance, if your data is structured like so:
And you want it to be structured like so:
You can parse it using the struct type.

Add values to a struct

To add values to structs, enclose the nested data with () in the SQL statement. For example, (1, true). Alternatively, you can also use ROW(1, true).

Examples

The statement below adds values to table x.
The statement below adds values to table y.
The statement below adds values to table trip.

Retrieve data in a struct

To retrieve data in a struct, enclose the struct name with () and use the dot operator to specify the nested column. For example, to access the initial_charge column under fare in the trip schema, use (fare).initial_charge.

Examples

Casting

Structs can be casted explicitly or implicitly to structs if the nested expressions and types can be casted.

Examples