<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>OpenText Analytics Database 26.2.x – Views</title>
    <link>/en/data-analysis/views/</link>
    <description>Recent content in Views on OpenText Analytics Database 26.2.x</description>
    <generator>Hugo -- gohugo.io</generator>
    
	  <atom:link href="/en/data-analysis/views/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Data-Analysis: Creating views</title>
      <link>/en/data-analysis/views/creating-views/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-analysis/views/creating-views/</guid>
      <description>
        
        
        &lt;p&gt;You can create two types of views:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../en/sql-reference/statements/create-statements/create-view/#&#34;&gt;CREATE VIEW&lt;/a&gt; creates a view that persists across all sessions until it is explicitly dropped with &lt;a href=&#34;../../../en/sql-reference/statements/drop-statements/drop-view/#&#34;&gt;DROP VIEW&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../en/sql-reference/statements/create-statements/create-local-temporary-view/#&#34;&gt;CREATE LOCAL TEMPORARY VIEW&lt;/a&gt; creates a view that is accessible only during the current database session, and only to its creator. The view is automatically dropped when the current session ends.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;After you create a view, you cannot change its definition. You can replace it with another view of the same name; or you can delete and redefine it.&lt;/p&gt;
&lt;p&gt;&lt;a name=&#34;View&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;permissions&#34;&gt;Permissions&lt;/h2&gt;
&lt;p&gt;To create a view, a non-superuser must have the following privileges:

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



&lt;tr&gt; 

&lt;th &gt;
Privilege&lt;/th&gt; 

&lt;th &gt;
Objects&lt;/th&gt;&lt;/tr&gt;

&lt;tr&gt; 

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

&lt;td &gt;
Schema where the view is created&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
DROP&lt;/td&gt; 

&lt;td &gt;
The view (only required if you specify an existing view in CREATE OR REPLACE VIEW)&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

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

&lt;td &gt;
Tables and views referenced by the view query&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

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

&lt;td &gt;
All schemas that contain tables and views referenced by the view query&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;For information about enabling users to access views, see &lt;a href=&#34;../../../en/data-analysis/views/using-views/#ViewAccessPermissions&#34;&gt;View Access Permissions&lt;/a&gt;.&lt;/p&gt;

      </description>
    </item>
    
    <item>
      <title>Data-Analysis: Using views</title>
      <link>/en/data-analysis/views/using-views/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-analysis/views/using-views/</guid>
      <description>
        
        
        &lt;p&gt;Views can be used in the &lt;code&gt;FROM&lt;/code&gt; clause of any SQL query or subquery. At execution, the database internally substitutes the name of the view used in the query with the actual query used in the view definition.&lt;/p&gt;
&lt;p&gt;&lt;a name=&#34;CREATE-V&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;create-view-example&#34;&gt;CREATE VIEW example&lt;/h2&gt;
&lt;p&gt;The following 
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/statements/create-statements/create-view/#&#34;&gt;CREATE VIEW&lt;/a&gt;&lt;/code&gt; statement creates the view &lt;code&gt;myview&lt;/code&gt;, which sums all individual incomes of customers listed in the &lt;code&gt;store.store_sales_fact&lt;/code&gt; table, and groups results by state:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE VIEW myview AS
   SELECT SUM(annual_income), customer_state FROM public.customer_dimension
     WHERE customer_key IN (SELECT customer_key FROM store.store_sales_fact)
     GROUP BY customer_state
     ORDER BY customer_state ASC;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can use this view to find all combined salaries greater than $2 billion:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT * FROM myview where sum &amp;gt; 2000000000 ORDER BY sum DESC;
     SUM     | customer_state
-------------+----------------
 29253817091 | CA
 14215397659 | TX
  5225333668 | MI
  4907216137 | CO
  4581840709 | IL
  3769455689 | CT
  3330524215 | FL
  3310667307 | IN
  2832710696 | TN
  2806150503 | PA
  2793284639 | MA
  2723441590 | AZ
  2642551509 | UT
  2128169759 | NV
(14 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;a name=&#34;ViewAccessPermissions&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;enabling-view-access&#34;&gt;Enabling view access&lt;/h2&gt;
&lt;p&gt;You can query any view that you create. To enable other non-superusers to access a view, you must:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Have SELECT...WITH GRANT OPTION privileges on the view&#39;s base table&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Grant users USAGE privileges on the view schema&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Grant users SELECT privileges to the view itself&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The following example grants &lt;code&gt;user2&lt;/code&gt; access to view &lt;code&gt;schema1.view1&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; GRANT USAGE ON schema schema1 TO user2;
=&amp;gt; GRANT SELECT ON schema1.view1 TO user2;
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;admonition important&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Important&lt;/h4&gt;
&lt;p&gt;If the view references an external table, you must also grant USAGE privileges to the external table&#39;s schema. So, if &lt;code&gt;schema1.view1&lt;/code&gt; references external table &lt;code&gt;schema2.extTable1&lt;/code&gt;, you must also grant &lt;code&gt;user2&lt;/code&gt; USAGE privileges to &lt;code&gt;schema2&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; GRANT USAGE on schema schema2 to user2;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;For more information see &lt;a href=&#34;../../../en/sql-reference/statements/grant-statements/grant-view/#&#34;&gt;GRANT (view)&lt;/a&gt;.&lt;/p&gt;

      </description>
    </item>
    
    <item>
      <title>Data-Analysis: View execution</title>
      <link>/en/data-analysis/views/view-execution/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-analysis/views/view-execution/</guid>
      <description>
        
        
        &lt;p&gt;When the database processes a query that contains a view, it treats the view as a subquery. The database executes the query by expanding it to include the query in the view definition. For example, the database expands the query on the view &lt;code&gt;myview&lt;/code&gt; shown in &lt;a href=&#34;../../../en/data-analysis/views/using-views/#CREATE V&#34;&gt;Using Views&lt;/a&gt;, to include the query that the view encapsulates, as follows:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; SELECT * FROM
   (SELECT SUM(annual_income), customer_state FROM public.customer_dimension
    WHERE customer_key IN
      (SELECT customer_key FROM store.store_sales_fact)
    GROUP BY customer_state
    ORDER BY customer_state ASC)
    AS ship where sum &amp;gt; 2000000000;
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;view-optimization&#34;&gt;View optimization&lt;/h2&gt;
&lt;p&gt;If you query a view and your query only includes columns from a subset of the tables that are joined in that view, the database executes that query by expanding it to include only those tables. This optimization requires one of the following conditions to be true:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Join columns are foreign and primary keys.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The join is a left or right outer join on columns with unique values.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;view-sort-order&#34;&gt;View sort order&lt;/h2&gt;
&lt;p&gt;When processing a query on a view, the database considers the &lt;code&gt;ORDER BY&lt;/code&gt; clause only in the outermost query. If the view definition includes an &lt;code&gt;ORDER BY&lt;/code&gt; clause, the database ignores it. Thus, in order to sort the results returned by a view, you must specify the &lt;code&gt;ORDER BY&lt;/code&gt; clause in the outermost query:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT * FROM &lt;span class=&#34;code-variable&#34;&gt;view-name&lt;/span&gt; ORDER BY &lt;span class=&#34;code-variable&#34;&gt;view-column&lt;/span&gt;;
&lt;/code&gt;&lt;/pre&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;

One exception applies: the database sorts view data when the view includes a &lt;code&gt;LIMIT&lt;/code&gt; clause. In this case, the database must sort the data before it can process the &lt;code&gt;LIMIT&lt;/code&gt; clause.

&lt;/div&gt;
&lt;p&gt;For example, the following view definition contains an &lt;code&gt;ORDER BY&lt;/code&gt; clause inside a &lt;code&gt;FROM&lt;/code&gt; subquery:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE VIEW myview AS SELECT SUM(annual_income), customer_state FROM public.customer_dimension
   WHERE customer_key IN
     (SELECT customer_key FROM store.store_sales_fact)
   GROUP BY customer_state
   ORDER BY customer_state ASC;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When you query the view, the database does not sort the data:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT * FROM myview WHERE SUM &amp;gt; 2000000000;
     SUM     | customer_state
-------------+----------------
  5225333668 | MI
  2832710696 | TN
 14215397659 | TX
  4907216137 | CO
  2793284639 | MA
  3769455689 | CT
  3310667307 | IN
  2723441590 | AZ
  2642551509 | UT
  3330524215 | FL
  2128169759 | NV
 29253817091 | CA
  4581840709 | IL
  2806150503 | PA
(14 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;To return sorted results, the outer query must include an &lt;code&gt;ORDER BY&lt;/code&gt; clause:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT * FROM myview WHERE SUM &amp;gt; 2000000000 ORDER BY customer_state ASC;
     SUM     | customer_state
-------------+----------------
  2723441590 | AZ
 29253817091 | CA
  4907216137 | CO
  3769455689 | CT
  3330524215 | FL
  4581840709 | IL
  3310667307 | IN
  2793284639 | MA
  5225333668 | MI
  2128169759 | NV
  2806150503 | PA
  2832710696 | TN
 14215397659 | TX
  2642551509 | UT
(14 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;run-time-errors&#34;&gt;Run-time errors&lt;/h2&gt;
&lt;p&gt;If the database does not have to evaluate an expression that would generate a run-time error in order to answer a query, the run-time error might not occur.&lt;/p&gt;
&lt;p&gt;For example, the following query returns an error, because &lt;code&gt;TO_DATE&lt;/code&gt; cannot convert the string &lt;code&gt;F&lt;/code&gt; to the specified date format:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT TO_DATE(&amp;#39;F&amp;#39;,&amp;#39;dd mm yyyy&amp;#39;) FROM customer_dimension;
   ERROR: Invalid input for DD: &amp;#34;F&amp;#34;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now create a view using the same query:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE VIEW temp AS SELECT TO_DATE(&amp;#39;F&amp;#39;,&amp;#39;dd mm yyyy&amp;#39;)
   FROM customer_dimension;
   CREATE VIEW
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In many cases, this view generates the same error message. For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT * FROM temp;
   ERROR: Invalid input for DD: &amp;#34;F&amp;#34;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;However, if you query that view with the &lt;code&gt;COUNT&lt;/code&gt; function, the database returns with the desired results:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT COUNT(*) FROM temp;
 COUNT
-------
   100
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This behavior works as intended. You can create views that contain subqueries, where not every row is intended to pass the predicate.&lt;/p&gt;

      </description>
    </item>
    
    <item>
      <title>Data-Analysis: Managing views</title>
      <link>/en/data-analysis/views/managing-views/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-analysis/views/managing-views/</guid>
      <description>
        
        
        &lt;h2 id=&#34;obtaining-view-information&#34;&gt;Obtaining view information&lt;/h2&gt;
&lt;p&gt;You can query system tables 
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/system-tables/v-catalog-schema/views/#&#34;&gt;VIEWS&lt;/a&gt;&lt;/code&gt; and 
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/system-tables/v-catalog-schema/view-columns/#&#34;&gt;VIEW_COLUMNS&lt;/a&gt;&lt;/code&gt; to obtain information about existing views—for example, a view&#39;s definition and the attributes of columns that comprise that view. You can also query system table 
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/system-tables/v-catalog-schema/view-tables/#&#34;&gt;VIEW_TABLES&lt;/a&gt;&lt;/code&gt; to examine view-related dependencies—for example, to determine how many views reference a table before you drop it.&lt;/p&gt;
&lt;h2 id=&#34;renaming-a-view&#34;&gt;Renaming a view&lt;/h2&gt;
&lt;p&gt;Use 
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/statements/alter-statements/alter-view/#&#34;&gt;ALTER VIEW&lt;/a&gt;&lt;/code&gt; to rename a view.&lt;/p&gt;
&lt;h2 id=&#34;dropping-a-view&#34;&gt;Dropping a view&lt;/h2&gt;
&lt;p&gt;Use 
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/statements/drop-statements/drop-view/#&#34;&gt;DROP VIEW&lt;/a&gt;&lt;/code&gt; to drop a view. Only the specified view is dropped. OpenText™ Analytics Database does not support &lt;code&gt;CASCADE&lt;/code&gt; functionality for views, and does not check for dependencies. Dropping a view causes any view that references it to fail.&lt;/p&gt;
&lt;h2 id=&#34;disabling-and-re-enabling-views&#34;&gt;Disabling and re-enabling views&lt;/h2&gt;
&lt;p&gt;If you drop a table that is referenced by a view, the database does not drop the view. However, attempts to use that view or access information about it from system table 
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/system-tables/v-catalog-schema/view-columns/#&#34;&gt;VIEW_COLUMNS&lt;/a&gt;&lt;/code&gt; return an error that the referenced table does not exist. If you restore that table, the database also re-enables usage of the view.&lt;/p&gt;

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