<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>OpenText Analytics Database 26.2.x – Complex types</title>
    <link>/en/data-load/complex-types/</link>
    <description>Recent content in Complex types on OpenText Analytics Database 26.2.x</description>
    <generator>Hugo -- gohugo.io</generator>
    
	  <atom:link href="/en/data-load/complex-types/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Data-Load: Structs</title>
      <link>/en/data-load/complex-types/structs/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-load/complex-types/structs/</guid>
      <description>
        
        
        &lt;p&gt;Columns can contain structs, which store property-value pairs. For example, a struct representing an address could have strings for the street address and city/state and an integer for the postal code:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;{ &amp;#34;street&amp;#34;:&amp;#34;150 Cambridgepark Dr.&amp;#34;,
  &amp;#34;city&amp;#34;:&amp;#34;Cambridge MA&amp;#34;,
  &amp;#34;postalcode&amp;#34;:02140}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Struct fields can be primitive types or other complex types.&lt;/p&gt;
&lt;p&gt;Use the &lt;a href=&#34;../../../en/sql-reference/data-types/complex-types/row/#&#34;&gt;ROW&lt;/a&gt; expression to define a struct column. In the following example, the data has columns for customer name, address, and account number, and the address is a struct in the data. The types you declare in the database must be compatible with the types in the data you load into them.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE customers (
    name VARCHAR,
    address ROW(street VARCHAR, city VARCHAR, zipcode INT),
    accountID INT);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Within the ROW, you specify the fields and their data types using the same syntax as for columns. Vertica treats the ROW as a single column for purposes of queries.&lt;/p&gt;
&lt;p&gt;Structs can contain other structs. In the following example, employees have various personal information, including an address which is itself a struct.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE employees(
    employeeID INT,
    personal ROW(
      name VARCHAR,
      address ROW(street VARCHAR, city VARCHAR, zipcode INT),
      taxID INT),
    department VARCHAR);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Structs can contain arrays of primitive types, arrays, or structs.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE customers(
  name VARCHAR,
  contact ROW(
    street VARCHAR,
    city VARCHAR,
    zipcode INT,
    email ARRAY[VARCHAR]
  ),
  accountid INT );
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When defining an external table with Parquet or ORC data, the definition of the table must match the schema of the data. For example, with the data used in the previous employees example, the following definition is an error:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE EXTERNAL TABLE employees(
    employeeID INT,
    personal ROW(
      name VARCHAR,
      address ROW(street VARCHAR, city VARCHAR),
      zipcode INT,
      taxID INT),
    department VARCHAR)
  AS COPY FROM &amp;#39;...&amp;#39; PARQUET;
ERROR 9151: Datatype mismatch [...]
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The data contains an address struct with three fields (street, city, zipcode), so the external table must also use a ROW with three fields. Changing the ROW to have two fields and promoting one of the fields to the parent ROW is a mismatch. Each ROW must match and, if structs are nested in the data, the complete structure must match.&lt;/p&gt;
&lt;p&gt;For native tables, you can specify which columns to load from the data, so you do not need to account for all of them. For the columns you load, the definition of the table must match the schema in the data file. Some parsers report fields found in that data that are not part of the table definition.&lt;/p&gt;
&lt;h2 id=&#34;handling-nulls&#34;&gt;Handling nulls&lt;/h2&gt;
&lt;p&gt;If a struct exists but a field value is null, the database assigns NULL as its value in the ROW. A struct where all fields are null is treated as a ROW with null fields. If the struct itself is null, the database reads the ROW as NULL.&lt;/p&gt;
&lt;h2 id=&#34;queries&#34;&gt;Queries&lt;/h2&gt;
&lt;p&gt;See &lt;a href=&#34;../../../en/data-analysis/queries/rows-structs/#&#34;&gt;Rows (structs)&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;restrictions&#34;&gt;Restrictions&lt;/h2&gt;
&lt;p&gt;ROW columns have several restrictions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Maximum nesting depth is 100.&lt;/li&gt;
&lt;li&gt;OpenText™ Analytics Database tables support up to 9800 columns and fields. The ROW itself is not counted, only its fields.&lt;/li&gt;
&lt;li&gt;ROW columns cannot use any constraints (such as NOT NULL) or defaults.&lt;/li&gt;
&lt;li&gt;ROW fields cannot be auto_increment or setof.&lt;/li&gt;
&lt;li&gt;ROW definition must include at least one field.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Row&lt;/code&gt; is a reserved keyword within a ROW definition, but is permitted as the name of a table or column.&lt;/li&gt;
&lt;li&gt;Tables containing ROW columns cannot also contain IDENTITY, default, SET USING, or named sequence columns.&lt;/li&gt;
&lt;/ul&gt;


      </description>
    </item>
    
    <item>
      <title>Data-Load: Arrays</title>
      <link>/en/data-load/complex-types/arrays/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-load/complex-types/arrays/</guid>
      <description>
        
        
        &lt;p&gt;Columns can contain arrays, which store ordered lists of elements of the same type. For example, an address column could use an array of strings to store multiple addresses that an individual might have, such as &lt;code&gt;[&#39;668 SW New Lane&#39;, &#39;518 Main Ave&#39;, &#39;7040 Campfire Dr&#39;]&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;There are two types of arrays:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Native array: a one-dimensional array of a primitive type.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Non-native array: all other supported arrays, including arrays that contain other arrays (multi-dimensional arrays) or structs (ROWs). Non-native arrays have some &lt;a href=&#34;#Restrict&#34;&gt;usage restrictions&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Use the &lt;a href=&#34;../../../en/sql-reference/data-types/complex-types/array/#&#34;&gt;ARRAY&lt;/a&gt; type to define an array column, specifying the type of its elements (a primitive type, a &lt;a href=&#34;../../../en/sql-reference/data-types/complex-types/row/#&#34;&gt;ROW&lt;/a&gt; (struct), or an array):&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE orders
   (orderkey    INT,
    custkey     INT,
    prodkey     ARRAY[VARCHAR(10)],
    orderprices ARRAY[DECIMAL(12,2)],
    orderdate   DATE
   );
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If an array is multi-dimensional, represent it as an array containing an array:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;ARRAY[ARRAY[FLOAT]]
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;queries&#34;&gt;Queries&lt;/h2&gt;
&lt;p&gt;See &lt;a href=&#34;../../../en/data-analysis/queries/arrays-and-sets-collections/#&#34;&gt;Arrays and sets (collections)&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a name=&#34;Restrict&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;restrictions&#34;&gt;Restrictions&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Native arrays support only data of primitive types, for example, int, UUID, and so on.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Array dimensionality is enforced. A column cannot contain arrays of varying dimensions. For example, a column that contains a three-dimensional array can only contain other three-dimensional arrays; it cannot simultaneously include a one-dimensional array. However, the arrays in a column can vary in size, where one array can contain four elements while another contains ten.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Array bounds, if specified, are enforced for all operations that load or alter data. Unbounded arrays may have as many elements as will fit in the allotted binary size.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;An array has a maximum binary size. If this size is not set when the array is defined, a default value is used.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Arrays do not support LONG types (like LONG VARBINARY or LONG VARCHAR) or user-defined types (like Geometry).&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;


      </description>
    </item>
    
    <item>
      <title>Data-Load: Flexible complex types</title>
      <link>/en/data-load/complex-types/flexible-complex-types/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-load/complex-types/flexible-complex-types/</guid>
      <description>
        
        
        &lt;p&gt;When defining tables, you can use strongly-typed complex types to fully describe any combination of structs and arrays. However, there are times when you might prefer not to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If the data contains a struct with a very large number of fields, and in your queries you will need only a few of them, you can avoid having to enumerate the rest in the table DDL. Further, a deeply-nested set of structs could exceed the nesting limit for the table if fully specified.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If the data schema is still evolving, you can delay finalizing strongly-typed DDL.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you anticipate the introduction of new fields in the data, you can use flexible types to discover them. A table with strong typing, on the other hand, would silently ignore those values. For an example of using flexible types to discover new fields, see &lt;a href=&#34;../../../en/data-load/data-formats/json-data/#Strong&#34;&gt;Strong and Flexible Typing&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Flexible types are a way to store complex or unstructured data as a binary blob in one column, in a way that allows access to individual elements of that data. This is the same approach that OpenText™ Analytics Database uses with &lt;a href=&#34;../../../en/flex-tables/understanding-flex-tables/&#34;&gt;flex tables&lt;/a&gt;, which support loading unstructured or semi-structured data. In a flex table, all data from a source is loaded into a single VMap column named &lt;code&gt;__raw__&lt;/code&gt;. From this column you can materialize other columns, such as a specific field in JSON data, or use special lookup functions in queries to read values directly out of the &lt;code&gt;__raw__&lt;/code&gt; column.&lt;/p&gt;
&lt;p&gt;The database uses a similar approach with complex types. You can describe the types fully using the &lt;a href=&#34;../../../en/sql-reference/data-types/complex-types/row/#&#34;&gt;ROW&lt;/a&gt; and &lt;a href=&#34;../../../en/sql-reference/data-types/complex-types/array/#&#34;&gt;ARRAY&lt;/a&gt; types in your table definition, or you can instead treat a complex type as a flexible type and not fully describe it. Each complex type that you choose to treat this way becomes its own flex-style column. You are not limited to a single column containing all data as in flex tables; instead, you can treat any complex type column, no matter how deeply it nests other types, as one flex-like column.&lt;/p&gt;
&lt;h2 id=&#34;defining-flexible-columns&#34;&gt;Defining flexible columns&lt;/h2&gt;
&lt;p&gt;To use a flexible complex type, declare the column as &lt;span class=&#34;sql&#34;&gt;LONG VARBINARY&lt;/span&gt;. You might also need to set other parameters in the parser, as described in the parser documentation.&lt;/p&gt;
&lt;p&gt;Consider a Parquet file with a restaurants table and the following columns:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;name: varchar&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;cuisine type: varchar&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;location (cities): array[varchar]&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;menu: array of structs, each struct having an item name and a price&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This data contains two complex columns, location (an array) and menu (an array of structs). The following example defines both columns as flexible columns by using &lt;span class=&#34;sql&#34;&gt;LONG VARBINARY&lt;/span&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE EXTERNAL TABLE restaurants(name VARCHAR, cuisine VARCHAR,
        location_city LONG VARBINARY, menu LONG VARBINARY)
    AS COPY FROM &amp;#39;/data/rest*.parquet&amp;#39;
    PARQUET(allow_long_varbinary_match_complex_type=&amp;#39;True&amp;#39;);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The &lt;code&gt;allow_long_varbinary_match_complex_type&lt;/code&gt; parameter is specific to the Parquet parser. It is required if you define any column as a flexible type. Without this parameter, the database tries to match the &lt;span class=&#34;sql&#34;&gt;LONG VARBINARY&lt;/span&gt; declaration in the table to a &lt;span class=&#34;sql&#34;&gt;VARBINARY&lt;/span&gt; column in the Parquet file, finds a complex type instead, and reports a data-type mismatch.&lt;/p&gt;
&lt;p&gt;You need not treat all complex columns as flexible types. The following definition is also valid:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE EXTERNAL TABLE restaurants(
            name VARCHAR, cuisine VARCHAR,
            location_city ARRAY[VARCHAR,50],
            menu LONG VARBINARY)
    AS COPY FROM &amp;#39;/data/rest*.parquet&amp;#39;
    PARQUET(allow_long_varbinary_match_complex_type=&amp;#39;True&amp;#39;);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For many common data formats, you can use the &lt;a href=&#34;../../../en/sql-reference/functions/management-functions/table-functions/infer-table-ddl/#&#34;&gt;INFER_TABLE_DDL&lt;/a&gt; function to derive a table definition from a data file. This function uses strong typing for complex types in almost all cases.&lt;/p&gt;
&lt;h2 id=&#34;querying-flexible-columns&#34;&gt;Querying flexible columns&lt;/h2&gt;
&lt;p&gt;Flexible columns are stored as &lt;span class=&#34;sql&#34;&gt;LONG VARBINARY&lt;/span&gt;, so selecting them directly produces unhelpful results. Instead, use the flex mapping functions to extract values from these columns. The &lt;a href=&#34;../../../en/sql-reference/functions/flex-functions/flex-map-functions/maptostring/#&#34;&gt;MAPTOSTRING&lt;/a&gt; function translates the complex type to JSON, as shown in the following example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT name, location_city, MAPTOSTRING(menu) AS menu FROM restaurants;
       name        |       location_city        |                    menu
-------------------+---------+------------------+----------------------------------------
 Bob&amp;#39;s pizzeria    | [&amp;#34;Cambridge&amp;#34;,&amp;#34;Pittsburgh&amp;#34;] | {
    &amp;#34;0&amp;#34;: {
        &amp;#34;item&amp;#34;: &amp;#34;cheese pizza&amp;#34;,
        &amp;#34;price&amp;#34;: &amp;#34;$8.25&amp;#34;
    },
    &amp;#34;1&amp;#34;: {
        &amp;#34;item&amp;#34;: &amp;#34;spinach pizza&amp;#34;,
        &amp;#34;price&amp;#34;: &amp;#34;$10.50&amp;#34;
    }
}
 Bakersfield Tacos | [&amp;#34;Pittsburgh&amp;#34;]             | {
    &amp;#34;0&amp;#34;: {
        &amp;#34;item&amp;#34;: &amp;#34;veggie taco&amp;#34;,
        &amp;#34;price&amp;#34;: &amp;#34;$9.95&amp;#34;
    },
    &amp;#34;1&amp;#34;: {
        &amp;#34;item&amp;#34;: &amp;#34;steak taco&amp;#34;,
        &amp;#34;price&amp;#34;: &amp;#34;$10.95&amp;#34;
    }
}
(2 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The menu column is an array of structs. Notice that the output is a set of key/value pairs, with the key being the array index. Bob&#39;s Pizzeria has two items on its menu, and each value is a struct. The first item (&amp;quot;0&amp;quot;) is a struct with an &amp;quot;item&amp;quot; value of &amp;quot;cheese pizza&amp;quot; and a &amp;quot;price&amp;quot; of &amp;quot;$8.25&amp;quot;.&lt;/p&gt;
&lt;p&gt;You can use keys to access specific values. The following example selects the first menu item from each restaurant. Note that all keys are strings, even array indexes:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT name, location_city, menu[&amp;#39;0&amp;#39;][&amp;#39;item&amp;#39;] AS item, menu[&amp;#39;0&amp;#39;][&amp;#39;price&amp;#39;] AS price FROM restaurants;
       name        |       location_city        |     item     | price
-------------------+----------------------------+--------------+-------
 Bob&amp;#39;s pizzeria    | [&amp;#34;Cambridge&amp;#34;,&amp;#34;Pittsburgh&amp;#34;] | cheese pizza | $8.25
 Bakersfield Tacos | [&amp;#34;Pittsburgh&amp;#34;]             | veggie taco  | $9.95
(2 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Instead of accessing specific indexes, you can use the &lt;a href=&#34;../../../en/sql-reference/functions/flex-functions/flex-map-functions/mapitems/#&#34;&gt;MAPITEMS&lt;/a&gt; function in a subquery to explode a flexible type, as in the following example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt;  SELECT name, location_city, menu_items[&amp;#39;item&amp;#39;], menu_items[&amp;#39;price&amp;#39;]
    FROM (SELECT mapitems(menu, name, location_city) OVER(PARTITION BEST)
         AS (indexes, menu_items, name, location_city)
    FROM restaurants) explode_menu;
       name        |       location_city        |  menu_items   | menu_items
-------------------+----------------------------+---------------+------------
 Bob&amp;#39;s pizzeria    | [&amp;#34;Cambridge&amp;#34;,&amp;#34;Pittsburgh&amp;#34;] | cheese pizza  | $8.25
 Bob&amp;#39;s pizzeria    | [&amp;#34;Cambridge&amp;#34;,&amp;#34;Pittsburgh&amp;#34;] | spinach pizza | $10.50
 Bakersfield Tacos | [&amp;#34;Pittsburgh&amp;#34;]             | veggie taco   | $9.95
 Bakersfield Tacos | [&amp;#34;Pittsburgh&amp;#34;]             | steak taco    | $10.95
(4 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For a complete list of flex mapping functions, see &lt;a href=&#34;../../../en/sql-reference/functions/flex-functions/flex-data-functions/#&#34;&gt;Flex data functions&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;json-and-avro-flexible-types&#34;&gt;JSON and Avro flexible types&lt;/h2&gt;
&lt;p&gt;The parsers for &lt;a href=&#34;../../../en/sql-reference/statements/copy/parsers/fjsonparser/&#34;&gt;JSON&lt;/a&gt; and &lt;a href=&#34;../../../en/sql-reference/statements/copy/parsers/favroparser/&#34;&gt;Avro&lt;/a&gt; support both flexible and strong types for complex types. When using flexible complex types or loading into a flex table, use the &lt;code&gt;flatten_maps&lt;/code&gt; and &lt;code&gt;flatten_arrays&lt;/code&gt; parameters to control how the parser handles complex data. These parsers ignore these parameters for strongly-typed complex types.&lt;/p&gt;
&lt;p&gt;The following example demonstrates the use of flexible complex types. Consider a JSON file containing the following data:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;{
    &amp;#34;name&amp;#34; : &amp;#34;Bob&amp;#39;s pizzeria&amp;#34;,
    &amp;#34;cuisine&amp;#34; : &amp;#34;Italian&amp;#34;,
    &amp;#34;location_city&amp;#34; : [&amp;#34;Cambridge&amp;#34;, &amp;#34;Pittsburgh&amp;#34;],
    &amp;#34;menu&amp;#34; : [{&amp;#34;item&amp;#34; : &amp;#34;cheese pizza&amp;#34;, &amp;#34;price&amp;#34; : &amp;#34;$8.25&amp;#34;},
              {&amp;#34;item&amp;#34; : &amp;#34;spinach pizza&amp;#34;, &amp;#34;price&amp;#34; : &amp;#34;$10.50&amp;#34;}]
}
{
    &amp;#34;name&amp;#34; : &amp;#34;Bakersfield Tacos&amp;#34;,
    &amp;#34;cuisine&amp;#34; : &amp;#34;Mexican&amp;#34;,
    &amp;#34;location_city&amp;#34; : [&amp;#34;Pittsburgh&amp;#34;],
    &amp;#34;menu&amp;#34; : [{&amp;#34;item&amp;#34; : &amp;#34;veggie taco&amp;#34;, &amp;#34;price&amp;#34; : &amp;#34;$9.95&amp;#34;},
              {&amp;#34;item&amp;#34; : &amp;#34;steak taco&amp;#34;, &amp;#34;price&amp;#34; : &amp;#34;$10.95&amp;#34;}]
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Create a table, using LONG VARBINARY for the flexible complex types, and load data specifying these parameters:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE restaurant(name VARCHAR, cuisine VARCHAR,
        location_city LONG VARBINARY, menu LONG VARBINARY);

=&amp;gt; COPY restaurant FROM &amp;#39;/data/restaurant.json&amp;#39;
   PARSER FJSONPARSER(&lt;span class=&#34;code-input&#34;&gt;flatten_maps=false, flatten_arrays=false&lt;/span&gt;);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can use Flex functions and direct access (through indexes) to return readable values:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT MAPTOSTRING(location_city), MAPTOSTRING(menu) FROM restaurant;
                   maptostring                   |             maptostring
-------------------------------------------------+--------------------------------------------------------
 {
    &amp;#34;0&amp;#34;: &amp;#34;Cambridge&amp;#34;,
    &amp;#34;1&amp;#34;: &amp;#34;Pittsburgh&amp;#34;
} | {
    &amp;#34;0&amp;#34;: {
        &amp;#34;item&amp;#34;: &amp;#34;cheese pizza&amp;#34;,
        &amp;#34;price&amp;#34;: &amp;#34;$8.25&amp;#34;
    },
    &amp;#34;1&amp;#34;: {
        &amp;#34;item&amp;#34;: &amp;#34;spinach pizza&amp;#34;,
        &amp;#34;price&amp;#34;: &amp;#34;$10.50&amp;#34;
    }
}
 {
    &amp;#34;0&amp;#34;: &amp;#34;Pittsburgh&amp;#34;
}                       | {
    &amp;#34;0&amp;#34;: {
        &amp;#34;item&amp;#34;: &amp;#34;veggie taco&amp;#34;,
        &amp;#34;price&amp;#34;: &amp;#34;$9.95&amp;#34;
    },
    &amp;#34;1&amp;#34;: {
        &amp;#34;item&amp;#34;: &amp;#34;steak taco&amp;#34;,
        &amp;#34;price&amp;#34;: &amp;#34;$10.95&amp;#34;
    }
}
(2 rows)

=&amp;gt; SELECT menu[&amp;#39;0&amp;#39;][&amp;#39;item&amp;#39;] FROM restaurant;
     menu
--------------
 cheese pizza
 veggie taco
(2 rows)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The COPY statement shown in this example sets &lt;code&gt;flatten_maps&lt;/code&gt; to false. Without that change, the keys for the complex columns would not work as expected, because record and array keys would be &amp;quot;flattened&amp;quot; at the top level. Querying menu[&#39;0&#39;][&#39;item&#39;] would produce no results. Instead, query flattened values as in the following example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT menu[&amp;#39;0.item&amp;#39;] FROM restaurant;
     menu
--------------
 veggie taco
 cheese pizza
(2 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Flattening directives apply to the entire COPY statement. You cannot flatten some columns and not others, or prevent flattening values in a complex column that is itself within a flattened flex table. Because flexible complex types and strongly-typed complex types require different values for flattening, you cannot combine strong and flexible complex types in the same load operation.&lt;/p&gt;


      </description>
    </item>
    
    <item>
      <title>Data-Load: System tables for complex types</title>
      <link>/en/data-load/complex-types/system-tables-complex-types/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-load/complex-types/system-tables-complex-types/</guid>
      <description>
        
        
        &lt;p&gt;Information about all complex types is recorded in the &lt;a href=&#34;../../../en/sql-reference/system-tables/v-catalog-schema/complex-types/#&#34;&gt;COMPLEX_TYPES&lt;/a&gt; system table. You must have read permission for the external table that uses a type to see its entries in this system table. Complex types are not shown in the &lt;a href=&#34;../../../en/sql-reference/system-tables/v-catalog-schema/types/#&#34;&gt;TYPES&lt;/a&gt; system table.&lt;/p&gt;
&lt;p&gt;For &lt;a href=&#34;../../../en/sql-reference/data-types/complex-types/row/#&#34;&gt;ROW&lt;/a&gt; types, each row in COMPLEX_TYPES represents one field of one ROW. The field name is the name used in the table definition if present, or a generated name beginning with _field otherwise. Each row also includes the (generated) name of its containing type, a string beginning with _ct_. (&amp;quot;CT&amp;quot; stands for &amp;quot;complex type&amp;quot;.)&lt;/p&gt;
&lt;p&gt;The following example defines one external table and then shows the types in COMPLEX_TYPES:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE EXTERNAL TABLE warehouse(
    name VARCHAR, id_map MAP&amp;lt;INT,VARCHAR&amp;gt;,
    data row(record INT, total FLOAT, description VARCHAR(100)),
    prices ARRAY[INT], comment VARCHAR(200), sales_total FLOAT, storeID INT)
  AS COPY FROM ... PARQUET;

=&amp;gt; SELECT type_id,type_kind,type_name,field_id,field_name,field_type_name,field_position
    FROM COMPLEX_TYPES ORDER BY type_id,field_name;

      type_id      | type_kind |       type_name       | field_id | field_name  | field_type_name | field_position
-------------------+-----------+-----------------------+----------+-------------+-----------------+----------------
 45035996274278280 | Map       | _ct_45035996274278280 |        6 | key         | int             |              0
 45035996274278280 | Map       | _ct_45035996274278280 |        9 | value       | varchar(80)     |              1
 45035996274278282 | Row       | _ct_45035996274278282 |        9 | description | varchar(80)     |              2
 45035996274278282 | Row       | _ct_45035996274278282 |        6 | record      | int             |              0
 45035996274278282 | Row       | _ct_45035996274278282 |        7 | total       | float           |              1
 45035996274278284 | Array     | _ct_45035996274278284 |        6 |             | int             |              0
(6 rows)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This table shows the fields for the two ROW types defined in the table. When a ROW contains another ROW, as is the case here with the nested address field, the field_type_name column uses the generated name of the contained ROW. The same number, minus the leading &amp;quot;&lt;em&gt;ct&lt;/em&gt;&amp;quot;, serves as the field_id.&lt;/p&gt;

      </description>
    </item>
    
  </channel>
</rss>
