<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>OpenText Analytics Database 26.2.x – Flattened tables</title>
    <link>/en/data-analysis/flattened-tables/</link>
    <description>Recent content in Flattened tables on OpenText Analytics Database 26.2.x</description>
    <generator>Hugo -- gohugo.io</generator>
    
	  <atom:link href="/en/data-analysis/flattened-tables/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Data-Analysis: Flattened table example</title>
      <link>/en/data-analysis/flattened-tables/flattened-table-example/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-analysis/flattened-tables/flattened-table-example/</guid>
      <description>
        
        
        &lt;p&gt;In the following example, columns &lt;code&gt;orderFact.cust_name&lt;/code&gt; and &lt;code&gt;orderFact.cust_gender&lt;/code&gt; are defined as SET USING and DEFAULT columns, respectively. Both columns obtain their values by querying table &lt;code&gt;custDim&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE public.custDim(
       cid int PRIMARY KEY NOT NULL,
       name varchar(20),
       age int,
      gender varchar(1)
);

=&amp;gt; CREATE TABLE public.orderFact(
       order_id int PRIMARY KEY NOT NULL,
       order_date timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
       cid int REFERENCES public.custDim(cid),
       cust_name varchar(20) &lt;span class=&#34;code-input&#34;&gt;SET USING&lt;/span&gt; (SELECT name FROM public.custDim WHERE (custDim.cid = orderFact.cid)),
       cust_gender varchar(1) &lt;span class=&#34;code-input&#34;&gt;DEFAULT&lt;/span&gt; (SELECT gender FROM public.custDim WHERE (custDim.cid = orderFact.cid)),
       amount numeric(12,2)
)
PARTITION BY order_date::DATE GROUP BY CALENDAR_HIERARCHY_DAY(order_date::DATE, 2, 2);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following INSERT commands load data into both tables:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; INSERT INTO custDim VALUES(1, &amp;#39;Alice&amp;#39;, 25, &amp;#39;F&amp;#39;);
=&amp;gt; INSERT INTO custDim VALUES(2, &amp;#39;Boz&amp;#39;, 30, &amp;#39;M&amp;#39;);
=&amp;gt; INSERT INTO custDim VALUES(3, &amp;#39;Eva&amp;#39;, 32, &amp;#39;F&amp;#39;);
=&amp;gt;
=&amp;gt; INSERT INTO orderFact (order_id, cid, amount) VALUES(100, 1, 15);
=&amp;gt; INSERT INTO orderFact (order_id, cid, amount) VALUES(200, 1, 1000);
=&amp;gt; INSERT INTO orderFact (order_id, cid, amount) VALUES(300, 2, -50);
=&amp;gt; INSERT INTO orderFact (order_id, cid, amount) VALUES(400, 3, 100);
=&amp;gt; INSERT INTO orderFact (order_id, cid, amount) VALUES(500, 2, 200);
=&amp;gt; COMMIT;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When you query the tables, the database returns the following result sets:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT * FROM custDim;
 cid | name  | age | gender
-----+-------+-----+--------
   1 | Alice |  25 | F
   2 | Boz   |  30 | M
   3 | Eva   |  32 | F
(3 rows)

=&amp;gt; SELECT order_id, order_date::date, cid, cust_name, cust_gender, amount FROM orderFact ORDER BY cid;
 order_id | order_date | cid | cust_name | cust_gender | amount
----------+------------+-----+-----------+-------------+---------
      100 | 2018-12-31 |   1 |           | F           |   15.00
      200 | 2018-12-31 |   1 |           | F           | 1000.00
      300 | 2018-12-31 |   2 |           | M           |  -50.00
      500 | 2018-12-31 |   2 |           | M           |  200.00
      400 | 2018-12-31 |   3 |           | F           |  100.00
(5 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The database automatically populates the DEFAULT column &lt;code&gt;orderFact.cust_gender&lt;/code&gt;, but the SET USING column &lt;code&gt;orderFact.cust_name&lt;/code&gt; remains NULL. You can automatically populate this column by calling the function &lt;a href=&#34;../../../en/sql-reference/functions/management-functions/projection-functions/refresh-columns/#&#34;&gt;REFRESH_COLUMNS&lt;/a&gt; on flattened table orderFact. This function invokes the SET USING query for column &lt;code&gt;orderFact.cust_name&lt;/code&gt; and populates the column from the result set:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT REFRESH_COLUMNS(&amp;#39;orderFact&amp;#39;, &amp;#39;cust_name&amp;#39;, &amp;#39;REBUILD&amp;#39;);

    REFRESH_COLUMNS
-------------------------------
refresh_columns completed
(1 row)

=&amp;gt; SELECT order_id, order_date::date, cid, cust_name, cust_gender, amount FROM orderFact ORDER BY cid;
 order_id | order_date | cid | cust_name | cust_gender | amount
----------+------------+-----+-----------+-------------+---------
      100 | 2018-12-31 |   1 | Alice     | F           |   15.00
      200 | 2018-12-31 |   1 | Alice     | F           | 1000.00
      300 | 2018-12-31 |   2 | Boz       | M           |  -50.00
      500 | 2018-12-31 |   2 | Boz       | M           |  200.00
      400 | 2018-12-31 |   3 | Eva       | F           |  100.00
(5 rows)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Data-Analysis: Creating flattened tables</title>
      <link>/en/data-analysis/flattened-tables/creating-flattened-tables/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-analysis/flattened-tables/creating-flattened-tables/</guid>
      <description>
        
        
        &lt;p&gt;A flattened table is typically a fact table where one or more columns query other tables for their values, through DEFAULT or SET USING constraints. DEFAULT and SET USING constraints can be used for columns of all data types. Like other columns, you can set these constraints when you create the flattened table, or any time thereafter by modifying the table DDL:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/statements/create-statements/create-table/#&#34;&gt;CREATE TABLE&lt;/a&gt;... (&lt;span class=&#34;code-variable&#34;&gt;column-name&lt;/span&gt; &lt;span class=&#34;code-variable&#34;&gt;data-type&lt;/span&gt; { DEFAULT | SET USING } &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt;)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/statements/alter-statements/alter-table/#&#34;&gt;ALTER TABLE...ADD COLUMN&lt;/a&gt; &lt;span class=&#34;code-variable&#34;&gt;column-name&lt;/span&gt; { DEFAULT | SET USING } &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/statements/alter-statements/alter-table/#&#34;&gt;ALTER TABLE...ALTER COLUMN&lt;/a&gt; &lt;span class=&#34;code-variable&#34;&gt;column-name&lt;/span&gt; { SET DEFAULT | SET USING } &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In all cases, the expressions that you set for these constraints are stored in the system table &lt;a href=&#34;../../../en/sql-reference/system-tables/v-catalog-schema/columns/#&#34;&gt;COLUMNS&lt;/a&gt;, in columns COLUMN_DEFAULT and COLUMN_SET_USING.&lt;/p&gt;
&lt;h2 id=&#34;supported-expressions&#34;&gt;Supported expressions&lt;/h2&gt;
&lt;p&gt;DEFAULT and SET USING generally support the same expressions. These include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Queries&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Other columns in the same table&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../en/sql-reference/language-elements/literals/&#34;&gt;Literals&lt;/a&gt; (constants)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;All &lt;a href=&#34;../../../en/sql-reference/language-elements/operators/&#34;&gt;operators&lt;/a&gt; supported by OpenText™ Analytics Database&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The following categories of functions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../en/sql-reference/functions/null-handling-functions/&#34;&gt;Null-handling&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../en/extending/developing-udxs/scalar-functions-udsfs/&#34;&gt;User-defined scalar&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../en/sql-reference/functions/system-information-functions/&#34;&gt;System information&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../en/sql-reference/functions/data-type-specific-functions/string-functions/&#34;&gt;String&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../en/sql-reference/functions/mathematical-functions/&#34;&gt;Mathematical&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../en/sql-reference/functions/formatting-functions/&#34;&gt;Formatting&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For more information about DEFAULT and SET USING expressions, including restrictions, see &lt;a href=&#34;../../../en/admin/working-with-native-tables/managing-table-columns/defining-column-values/#&#34;&gt;Defining column values&lt;/a&gt;.&lt;/p&gt;

      </description>
    </item>
    
    <item>
      <title>Data-Analysis: Required privileges</title>
      <link>/en/data-analysis/flattened-tables/required-privileges/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-analysis/flattened-tables/required-privileges/</guid>
      <description>
        
        
        &lt;p&gt;The following operations on flattened table require privileges as shown:

&lt;table class=&#34;table table-bordered&#34; &gt;



&lt;tr&gt; 

&lt;th &gt;
Operation&lt;/th&gt; 

&lt;th &gt;
Object&lt;/th&gt; 

&lt;th &gt;
Privileges&lt;/th&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td  rowspan=&#34;2&#34; &gt;
Retrieve data from a flattened table.&lt;/td&gt; 

&lt;td &gt;
Schema&lt;/td&gt; 

&lt;td &gt;
USAGE&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
Flattened table&lt;/td&gt; 

&lt;td &gt;
SELECT&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td  rowspan=&#34;3&#34; &gt;
Add SET USING or DEFAULT columns to a table.&lt;/td&gt; 

&lt;td &gt;
Schemas (queried/flattened tables)&lt;/td&gt; 

&lt;td &gt;
USAGE&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
Queried tables&lt;/td&gt; 

&lt;td &gt;
SELECT&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
Target table&lt;/td&gt; 

&lt;td &gt;
CREATE&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td  rowspan=&#34;3&#34; &gt;
INSERT data on a flattened table with SET USING and/or DEFAULT columns.&lt;/td&gt; 

&lt;td &gt;
Schemas (queried/flattened tables)&lt;/td&gt; 

&lt;td &gt;
USAGE&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
Queried tables&lt;/td&gt; 

&lt;td &gt;
SELECT&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
Flattened table&lt;/td&gt; 

&lt;td &gt;
INSERT&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td  rowspan=&#34;3&#34; &gt;
Run &lt;a href=&#34;../../../en/sql-reference/functions/management-functions/projection-functions/refresh-columns/#&#34;&gt;REFRESH_COLUMNS&lt;/a&gt; on a flattened table.&lt;/td&gt; 

&lt;td &gt;
Schemas (queried/flattened tables)&lt;/td&gt; 

&lt;td &gt;
USAGE&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
Queried tables&lt;/td&gt; 

&lt;td &gt;
SELECT&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
Flattened table&lt;/td&gt; 

&lt;td &gt;
SELECT, UPDATE&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/p&gt;

      </description>
    </item>
    
    <item>
      <title>Data-Analysis: DEFAULT versus SET USING</title>
      <link>/en/data-analysis/flattened-tables/default-versus-set-using/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-analysis/flattened-tables/default-versus-set-using/</guid>
      <description>
        
        
        &lt;p&gt;Columns in a flattened table can query other tables with constraints DEFAULT and SET USING. In both cases, changes in the queried tables are not automatically propagated to the flattened table. The two constraints differ as follows:&lt;/p&gt;
&lt;p&gt;&lt;a name=&#34;DEFAULT&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;default-columns&#34;&gt;DEFAULT columns&lt;/h2&gt;
&lt;p&gt;The database typically executes DEFAULT queries on new rows when they are added to the flattened table, through load operations such as INSERT and COPY, or when you create or alter a table with a new column that specifies a DEFAULT expression. In all cases, values in existing rows, including other columns with DEFAULT expressions, remain unchanged.&lt;/p&gt;
&lt;p&gt;To refresh a column&#39;s default values, you must explicitly call &lt;a href=&#34;../../../en/sql-reference/statements/update/#&#34;&gt;UPDATE&lt;/a&gt; on that column as follows:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; UPDATE &lt;span class=&#34;code-variable&#34;&gt;table-name&lt;/span&gt; SET &lt;span class=&#34;code-variable&#34;&gt;column-name&lt;/span&gt;=DEFAULT;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;a name=&#34;SET&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;set-using-columns&#34;&gt;SET USING columns&lt;/h2&gt;
&lt;p&gt;The database executes SET USING queries only when you invoke the function &lt;a href=&#34;../../../en/sql-reference/functions/management-functions/projection-functions/refresh-columns/#&#34;&gt;REFRESH_COLUMNS&lt;/a&gt;. Load operations set SET USING columns in new rows to NULL. After the load, you must call REFRESH_COLUMNS to populate these columns from the queried tables. This can be useful in two ways: you can defer the overhead of updating the flattened table to any time that is convenient; and you can repeatedly query source tables for new data.&lt;/p&gt;
&lt;p&gt;SET USING is especially useful for large flattened tables that reference data from multiple dimension tables. Often, only a small subset of SET USING columns are subject to change, and queries on the flattened table do not always require up-to-the-minute data. Given this scenario, you can refresh table content at regular intervals, or only during off-peak hours. One or both of these strategies can minimize overhead, and facilitate performance when querying large data sets.&lt;/p&gt;
&lt;p&gt;You can control the scope of the refresh operation by calling REFRESH _COLUMNS in one of two modes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;UPDATE : Marks original rows as deleted and replaces them with new rows. In order to save these updates, you must issue a COMMIT statement.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;REBUILD: Replaces all data in the specified columns. The rebuild operation is auto-committed.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If a flattened table is partitioned, you can reduce the overhead of calling REFRESH_COLUMNS in REBUILD mode by specifying one or more partition keys. Doing so limits the rebuild operation to the specified partitions. For details, see &lt;a href=&#34;../../../en/sql-reference/functions/management-functions/projection-functions/refresh-columns/#Partitio&#34;&gt;Partition-based REBUILD Operations&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

Examples use the &lt;code&gt;custDim&lt;/code&gt; and &lt;code&gt;orderFact&lt;/code&gt; tables described in &lt;a href=&#34;../../../en/data-analysis/flattened-tables/flattened-table-example/#&#34;&gt;Flattened table example&lt;/a&gt;.

&lt;/div&gt;
&lt;p&gt;The following &lt;a href=&#34;../../../en/sql-reference/statements/update/#&#34;&gt;UPDATE&lt;/a&gt; statement updates the &lt;code&gt;custDim&lt;/code&gt; table:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; UPDATE custDim SET name=&amp;#39;Roz&amp;#39;, gender=&amp;#39;F&amp;#39; WHERE cid=2;
 OUTPUT
--------
      1
(1 row)

=&amp;gt; COMMIT;
COMMIT
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Changes are not propagated to flattened table &lt;code&gt;orderFact&lt;/code&gt;, which includes SET USING and DEFAULT columns &lt;code&gt;cust_name&lt;/code&gt; and &lt;code&gt;cust_gender&lt;/code&gt;, respectively:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; SELECT * FROM custDim ORDER BY cid;
 cid | name  | age | gender
-----+-------+-----+--------
   1 | Alice |  25 | F
   2 | Roz   |  30 | F
   3 | Eva   |  32 | F
(3 rows)

=&amp;gt; SELECT order_id, order_date::date, cid, cust_name, cust_gender, amount FROM orderFact ORDER BY cid;
 order_id | order_date | cid | cust_name | cust_gender | amount
----------+------------+-----+-----------+-------------+---------
      100 | 2018-12-31 |   1 | Alice     | F           |   15.00
      200 | 2018-12-31 |   1 | Alice     | F           | 1000.00
      300 | 2018-12-31 |   2 | Boz       | M           |  -50.00
      500 | 2018-12-31 |   2 | Boz       | M           |  200.00
      400 | 2018-12-31 |   3 | Eva       | F           |  100.00
(5 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following INSERT statement invokes the &lt;code&gt;cust_gender&lt;/code&gt; column&#39;s DEFAULT query and sets that column to &lt;code&gt;F&lt;/code&gt;. The load operation does not invoke the &lt;code&gt;cust_name&lt;/code&gt; column&#39;s SET USING query, so &lt;code&gt;cust_name&lt;/code&gt; is set to null:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; INSERT INTO orderFact(order_id, cid, amount)  VALUES(500, 3, 750);
 OUTPUT
--------
      1
(1 row)

=&amp;gt; COMMIT;
COMMIT
=&amp;gt;  SELECT order_id, order_date::date, cid, cust_name, cust_gender, amount FROM orderFact ORDER BY cid;
 order_id | order_date | cid | cust_name | cust_gender | amount
----------+------------+-----+-----------+-------------+---------
      100 | 2018-12-31 |   1 | Alice     | F           |   15.00
      200 | 2018-12-31 |   1 | Alice     | F           | 1000.00
      300 | 2018-12-31 |   2 | Boz       | M           |  -50.00
      500 | 2018-12-31 |   2 | Boz       | M           |  200.00
      400 | 2018-12-31 |   3 | Eva       | F           |  100.00
      500 | 2018-12-31 |   3 |           | F           |  750.00
(6 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;To update the values in &lt;code&gt;cust_name&lt;/code&gt;, invoke its SET USING query by calling REFRESH_COLUMNS. REFRESH_COLUMNS executes &lt;code&gt;cust_name&lt;/code&gt;&#39;s SET USING query: it queries the &lt;code&gt;name&lt;/code&gt; column in table &lt;code&gt;custDim&lt;/code&gt; and updates &lt;code&gt;cust_name&lt;/code&gt; with the following values:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Sets &lt;code&gt;cust_name&lt;/code&gt; in the new row to &lt;code&gt;Eva&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Returns updated values for &lt;code&gt;cid=2&lt;/code&gt;, and changes &lt;code&gt;Boz&lt;/code&gt; to &lt;code&gt;Roz&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT REFRESH_COLUMNS (&amp;#39;orderFact&amp;#39;,&amp;#39;&amp;#39;);
      REFRESH_COLUMNS
---------------------------
 refresh_columns completed
(1 row)

=&amp;gt; COMMIT;
COMMIT
=&amp;gt;  SELECT order_id, order_date::date, cid, cust_name, cust_gender, amount FROM orderFact ORDER BY cid;
 order_id | order_date | cid | cust_name | cust_gender | amount
----------+------------+-----+-----------+-------------+---------
      100 | 2018-12-31 |   1 | Alice     | F           |   15.00
      200 | 2018-12-31 |   1 | Alice     | F           | 1000.00
      300 | 2018-12-31 |   2 | Roz       | M           |  -50.00
      500 | 2018-12-31 |   2 | Roz       | M           |  200.00
      400 | 2018-12-31 |   3 | Eva       | F           |  100.00
      500 | 2018-12-31 |   3 | Eva       | F           |  750.00
(6 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;REFRESH_COLUMNS only affects the values in column &lt;code&gt;cust_name&lt;/code&gt;. Values in column &lt;code&gt;gender&lt;/code&gt; are unchanged, so settings for rows where &lt;code&gt;cid=2&lt;/code&gt; (&lt;code&gt;Roz&lt;/code&gt;) remain set to &lt;code&gt;M&lt;/code&gt;. To repopulate &lt;code&gt;orderFact.cust_gender&lt;/code&gt; with default values from &lt;code&gt;custDim.gender&lt;/code&gt;, call UPDATE on &lt;code&gt;orderFact&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; UPDATE orderFact SET cust_gender=DEFAULT WHERE cust_name=&amp;#39;Roz&amp;#39;;
 OUTPUT
--------
      2
(1 row)

=&amp;gt; COMMIT;
COMMIT
=&amp;gt; SELECT order_id, order_date::date, cid, cust_name, cust_gender, amount FROM orderFact ORDER BY cid;
 order_id | order_date | cid | cust_name | cust_gender | amount
----------+------------+-----+-----------+-------------+---------
      100 | 2018-12-31 |   1 | Alice     | F           |   15.00
      200 | 2018-12-31 |   1 | Alice     | F           | 1000.00
      300 | 2018-12-31 |   2 | Roz       | F           |  -50.00
      500 | 2018-12-31 |   2 | Roz       | F           |  200.00
      400 | 2018-12-31 |   3 | Eva       | F           |  100.00
      500 | 2018-12-31 |   3 | Eva       | F           |  750.00
(6 rows)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Data-Analysis: Modifying SET USING and DEFAULT columns</title>
      <link>/en/data-analysis/flattened-tables/modifying-set-using-and-default-columns/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-analysis/flattened-tables/modifying-set-using-and-default-columns/</guid>
      <description>
        
        
        
&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

Examples use the &lt;code&gt;custDim&lt;/code&gt; and &lt;code&gt;orderFact&lt;/code&gt; tables described in &lt;a href=&#34;../../../en/data-analysis/flattened-tables/flattened-table-example/#&#34;&gt;Flattened table example&lt;/a&gt;.

&lt;/div&gt;
&lt;h2 id=&#34;modifying-a-set-using-and-default-expression&#34;&gt;Modifying a SET USING and DEFAULT expression&lt;/h2&gt;
&lt;p&gt;&lt;a href=&#34;../../../en/sql-reference/statements/alter-statements/alter-table/&#34;&gt;ALTER TABLE...ALTER COLUMN&lt;/a&gt; can set an existing column to SET USING or DEFAULT, or change the query expression of an existing SET USING or DEFAULT column. In both cases, existing values remain unchanged. The database refreshes column values in the following cases:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;DEFAULT column: Refreshed only when you load new rows, or when you invoke UPDATE to set column values to &lt;code&gt;DEFAULT&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;SET USING column: Refreshed only when you call &lt;a href=&#34;../../../en/sql-reference/functions/management-functions/projection-functions/refresh-columns/#&#34;&gt;REFRESH_COLUMNS&lt;/a&gt; on the table.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For example, you might set an entire column to NULL as follows:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; ALTER TABLE orderFact ALTER COLUMN cust_name SET USING NULL;
ALTER TABLE
=&amp;gt; SELECT REFRESH_COLUMNS(&amp;#39;orderFact&amp;#39;, &amp;#39;cust_name&amp;#39;, &amp;#39;REBUILD&amp;#39;);
REFRESH_COLUMNS
---------------------------
refresh_columns completed
(1 row)

=&amp;gt; SELECT order_id, order_date::date, cid, cust_name, cust_gender, amount FROM orderFact ORDER BY cid;
  order_id | order_date | cid | cust_name | cust_gender | amount
 ----------+------------+-----+-----------+-------------+---------
    100 | 2018-12-31 |   1 |           | F           |   15.00
    200 | 2018-12-31 |   1 |           | F           | 1000.00
    300 | 2018-12-31 |   2 |           | M           |  -50.00
    500 | 2018-12-31 |   2 |           | M           |  200.00
    400 | 2018-12-31 |   3 |           | F           |  100.00
(5 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For details, see &lt;a href=&#34;../../../en/admin/working-with-native-tables/managing-table-columns/defining-column-values/#&#34;&gt;Defining column values&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;removing-set-using-and-default-constraints&#34;&gt;Removing SET USING and DEFAULT constraints&lt;/h2&gt;
&lt;p&gt;You remove a column&#39;s &lt;code&gt;SET USING&lt;/code&gt; or &lt;code&gt;DEFAULT&lt;/code&gt; constraint with &lt;a href=&#34;../../../en/sql-reference/statements/alter-statements/alter-table/&#34;&gt;ALTER TABLE...ALTER COLUMN&lt;/a&gt;, as follows:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;ALTER TABLE &lt;span class=&#34;code-variable&#34;&gt;table-name&lt;/span&gt; ALTER COLUMN &lt;span class=&#34;code-variable&#34;&gt;column-name&lt;/span&gt; DROP { SET USING | DEFAULT };
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The database removes the constraint from the specified column, but the column and its data are otherwise unaffected. For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; ALTER TABLE orderFact ALTER COLUMN cust_name DROP SET USING;
ALTER TABLE
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;dropping-columns-queried-by-set-using-or-default&#34;&gt;Dropping columns queried by SET USING or DEFAULT&lt;/h2&gt;
&lt;p&gt;The database enforces dependencies between a flattened table and the tables that it queries. Attempts to drop a queried column or its table return an error unless the drop operation also includes the &lt;code&gt;CASCADE&lt;/code&gt; option. The database implements &lt;code&gt;CASCADE&lt;/code&gt; by removing the SET USING or DEFAULT constraint from the flattened table. The table column and its data are otherwise unaffected.&lt;/p&gt;
&lt;p&gt;For example, attempts to drop column &lt;code&gt;name&lt;/code&gt; in table &lt;code&gt;custDim&lt;/code&gt; returns a rollback error, as this column is referenced by SET USING column &lt;code&gt;orderFact.cust_gender&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; ALTER TABLE custDim DROP COLUMN gender;
ROLLBACK 7301:  Cannot drop column &amp;#34;gender&amp;#34; since it is referenced in the default expression of table &amp;#34;public.orderFact&amp;#34;, column &amp;#34;cust_gender&amp;#34;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;To drop this column, use the &lt;code&gt;CASCADE&lt;/code&gt; option:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; ALTER TABLE custDim DROP COLUMN gender CASCADE;
ALTER TABLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The database removes the DEFAULT constraint from &lt;code&gt;orderFact.cust_gender&lt;/code&gt; as part of the drop operation. However, &lt;code&gt;cust_gender&lt;/code&gt; retains the data that it previously queried from the dropped column &lt;code&gt;custDim.gender&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT EXPORT_TABLES(&amp;#39;&amp;#39;,&amp;#39;orderFact&amp;#39;);
                                                EXPORT_TABLES
------------------------------------------------------------------------------------------------------------
CREATE TABLE public.orderFact
(
    order_id int NOT NULL,
    order_date timestamp NOT NULL DEFAULT (now())::timestamptz(6),
    cid int,
    cust_name varchar(20),
    cust_gender varchar(1) SET USING NULL,
    amount numeric(12,2),
    CONSTRAINT C_PRIMARY PRIMARY KEY (order_id) DISABLED
)
PARTITION BY ((orderFact.order_date)::date) GROUP BY (CASE WHEN (&amp;#34;datediff&amp;#34;(&amp;#39;year&amp;#39;, (orderFact.order_date)::date, ((now())::timestamptz(6))::date) &amp;gt;= 2) THEN (date_trunc(&amp;#39;year&amp;#39;, (orderFact.order_date)::date))::date WHEN (&amp;#34;datediff&amp;#34;(&amp;#39;month&amp;#39;, (orderFact.order_date)::date, ((now())::timestamptz(6))::date) &amp;gt;= 2) THEN (date_trunc(&amp;#39;month&amp;#39;, (orderFact.order_date)::date))::date ELSE (orderFact.order_date)::date END);
ALTER TABLE public.orderFact ADD CONSTRAINT C_FOREIGN FOREIGN KEY (cid) references public.custDim (cid);

(1 row)

=&amp;gt; SELECT * FROM orderFact;
 order_id |         order_date         | cid | cust_name | cust_gender | amount
----------+----------------------------+-----+-----------+-------------+---------
      400 | 2021-01-05 13:27:56.026115 |   3 |           | F           |  100.00
      300 | 2021-01-05 13:27:56.026115 |   2 |           | F           |  -50.00
      200 | 2021-01-05 13:27:56.026115 |   1 |           | F           | 1000.00
      500 | 2021-01-05 13:30:18.138386 |   3 |           | F           |  750.00
      100 | 2021-01-05 13:27:56.026115 |   1 |           | F           |   15.00
      500 | 2021-01-05 13:27:56.026115 |   2 |           | F           |  200.00
(6 rows)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Data-Analysis: Rewriting SET USING queries</title>
      <link>/en/data-analysis/flattened-tables/rewriting-set-using-queries/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-analysis/flattened-tables/rewriting-set-using-queries/</guid>
      <description>
        
        
        &lt;p&gt;When you call &lt;a href=&#34;../../../en/sql-reference/functions/management-functions/projection-functions/refresh-columns/#&#34;&gt;REFRESH_COLUMNS&lt;/a&gt; on a &lt;a href=&#34;../../../en/data-analysis/flattened-tables/&#34;&gt;flattened table&lt;/a&gt;&#39;s &lt;a href=&#34;../../../en/admin/working-with-native-tables/managing-table-columns/defining-column-values/&#34;&gt;SET USING&lt;/a&gt; (or DEFAULT USING) column, it executes the SET USING query by joining the target and source tables. By default, the source table is always the inner table of the join. In most cases, cardinality of the source table is less than the target table, so REFRESH_COLUMNS executes the join efficiently.&lt;/p&gt;
&lt;p&gt;Occasionally—notably, when you call REFRESH_COLUMNS on a partitioned table—the source table can be larger than the target table. In this case, performance of the join operation can be suboptimal.&lt;/p&gt;
&lt;p&gt;You can address this issue by enabling configuration parameter &lt;a href=&#34;../../../en/sql-reference/config-parameters/projection-parameters/#RewriteQueryForLargeDim&#34;&gt;RewriteQueryForLargeDim&lt;/a&gt;. When enabled (1), the database rewrites the query, by reversing the inner and outer join between the target and source tables.

&lt;div class=&#34;admonition important&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Important&lt;/h4&gt;
Enable this parameter only if the SET USING source data is in a table that is larger than the target table. If the source data is in a table smaller than the target table, then enabling RewriteQueryForLargeDim can adversely affect refresh performance.
&lt;/div&gt;&lt;/p&gt;


      </description>
    </item>
    
    <item>
      <title>Data-Analysis: Impact of SET USING columns on license limits</title>
      <link>/en/data-analysis/flattened-tables/impact-of-set-using-columns-on-license-limits/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-analysis/flattened-tables/impact-of-set-using-columns-on-license-limits/</guid>
      <description>
        
        
        &lt;p&gt;OpenText™ Analytics Database does not count the data in denormalized columns towards your raw data license limit. SET USING columns obtain their data by querying columns in other tables. Only data from the source tables counts against your raw data license limit.&lt;/p&gt;
&lt;p&gt;For a list of SET USING restrictions, see &lt;a href=&#34;../../../en/admin/working-with-native-tables/managing-table-columns/defining-column-values/#&#34;&gt;Defining column values&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You can remove a SET USING column so it counts toward your license limit with the following command:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; ALTER TABLE table1 ALTER COLUMN column1 DROP SET USING;
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
  </channel>
</rss>
