How can I append data onto a view using sql? - sql

I have created a view using the following sql command:
CREATE OR REPLACE VIEW Table AS
SELECT * FROM TABLEA FULL OUTER JOIN TABLEB
ON TABLEA.Column1=TABLEB.Column1
I usually get new datasets every week and I was wondering if there was a way using sql commands to append the data from the new table onto the view, "Table"?
Thanks in advance.

A view in SQL, so long as it is not a materialized view, basically just sits on top of the underlying table. So, for a non materialized view, if you want it to see new data, that data would have to come from the underlying tables. If you have a materialized view, then you may just insert however many rows you want.

Related

Where used list in BigQuery

I have a view, Wanted to check what sort of SQL can help to identify list of all views and Stored procedure using it.
For Example,
View A is being used in View B, View C and Stored Procedure D.
Is there any metadata schema which can help writing such query where we can track all dependent objects of a certain object in BigQuery. Please assist.
For Example,
View A is being used in View B, View C and Stored Procedure D.
Is there any metadata schema which can help writing such query where we can track all dependent objects of a certain object in BigQuery. Please assist.
You can run the following query that will list all views, this can be done on an individual dataset basis. Of course if you have a set of datasets you could create one UNION ALL query for each dataset to combine the results.
SELECT * FROM dataset_name.INFORMATION_SCHEMA.VIEWS WHERE
REGEXP_CONTAINS(view_definition, 'dataset_name.table_name')
Replacing dataset_name and table_name in the above query.
view_definition in the schema table contains the actual SQL code to create the view. So we are essentially just searching that field for the table name, same would work if you are looking for a view being used in a view.

Azure SQL: Is it possible to use the view from another database?

Being new to Azure SQL, I am already successfully JOINing my table with the table from the other database (by defining the CREATE EXTERNAL TABLE and the related things). However, some queries contain views from the other database, not the tables. How can I join my table with that external view? Is it possible at all? Or do I have to copy the code from the remote view and work directly with the external tables?
with create external table you can access a table or view :
take a look at
https://medium.com/#fbeltrao/access-another-database-in-azure-sql-1afc526b7ad4

How to set up a view that replaces a table once processed?

Every time I attempt to save a view that has "create or replace table" I get the error:Only SELECT statements are allowed in view queries.
I am using standard SQL in Google Cloud Big Query. I do not want the view as a scheduled query and the view is too large to run, meaning it errors out asking for me to create a table that allows large results. I want the query to update its associated table every time it is run. I came across the Write_Truncate syntax, however I do not know to use it.
create or replace table.test1 as( all my other queries)
I just expect for big query to allow me to run the table.

Hive view has no path?

I've tried to make a Hive view so we can start sqooping on the columns we need.
The statement used to create the view:
CREATE VIEW new_view (col1, col2, col3)
AS SELECT col1, col2, col3 FROM source_table;
However the view has no perceived location within our Hadoop cluster. What's odd if we run a SELECT * FROM new_view; we get the data.
But when we try to run an Oozie job to hook into the view we get a table not found error. The table isn't in file browser either.
Reason why you are getting this error is that your view doesn't have any HDFS location to it. Sqoop export looks for export-dir but since your view don't contain any location to it, you are getting this error.
A view is just a layer of abstraction on top of your Hive table (which redirects to HDFS location associated to it). Please find below view definition:
A VIEW statement lets you create a shorthand abbreviation for a more
complicated query.The base query can involve joins, expressions,
reordered columns, column aliases,and other SQL features that can make
a query hard to understand or maintain.It is purely a logical
construct (an alias for a query) with no physical data behind it.
You may have to use the source_table for sqoop-export.
Note that a view is a purely logical object with no associated storage.
When a query references a view, the view's definition is evaluated in order to produce a set of rows for further processing by the query.
You can consider reading :- https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-Create/Drop/AlterView
So you might think of storing the view data in a table in order to access it from oozie.

Query driving a view and actual view not returning same results

I have a view that is returning four columns of data to be pushed to an external program. When I simply query the view ("Select * from schema.view_name") I get 10353 rows. When I run the actual SQL that created the view (I literally copied and pasted what Oracle had stored, minus the "Create or Replace" statement), I get 238745 rows.
Any ideas why this might occur?
Best guess: when you run the query standalone you're not running it in the same schema the view was created in (I am inferring this from the fact that you included the schema name in your example SELECT). The schema where you're running the query either has its own table with the same name as one of the base tables in the view, or one of the names is a synonym pointing to yet another view that contains only a subset of the rows in the underlying table.