I created view myview with two columns ID and Name. But I want add extra column for this.
I using the query as :
ALTER VIEW myview ADD COLUMNS (AGE int);
But I am getting error as:
required (...)+ loop did not match anything at input 'columns' in add
partition statement.
Any help me in this?
You will have to get the new column from the table from which the view was created.
alter view myview as select col_1 ,col_2 ,Age from your_table
Related
For BigQuery tables, I can add column descriptions via the column options list like
create or replace table
`my_dataset.my_table`(col INTEGER OPTIONS(description="My column description"))
as
select 1 col
It looks like the same is currently not supported for views. So the following doesn't work.
create or replace view
`my_dataset.my_view`(col OPTIONS(description="My column description"))
as
select *
from `my_dataset.my_table`
How can I add a view column description with a DML statement?
I am creating a trigger in SQL to sum up all the values in a column after a change is made. I am stuck and encountering an error when I try this:
`
CREATE OR REPLACE TRIGGER GET_NUM_ATHLETES
AFTER DELETE OR UPDATE OF NUM_ATHLETES OR INSERT ON DELEGATION
BEGIN
SELECT
SUM("A1"."NUM_") "SUM(NUM_)"
INTO x_1 FROM
"DBF19"."DELEGATION" "A1";
END;
`
My table looks like this:
ID
Num_
ABC
2
XYZ
4
I just used the Oracle SQL Developer GUI to create, but obviously doing something wrong.
You could use a view instead of maintaining the data in a table. That way the view would get the results "live" each time.
And also you wouldn't need to do the extra task of loading data into another table
CREATE VIEW NUM_ATHLETES
AS
SELECT SUM("A1"."NUM_") "SUM(NUM_)"
FROM "DBF19"."DELEGATION" "A1";
Do not create a table, use a VIEW (or if you were doing more complicated calculations a MATERIALIZED VIEW):
DROP TABLE num_athletes;
then:
CREATE VIEW num_athletes (id, num) AS
SELECT id, SUM(num_)
FROM DBF19.DELEGATION
GROUP BY id;
In GCP BigQuery, Can we add a column to an existing table and change his order in the table ?
for the moment I found only one way which is to delete the table modify the JSON of the table and recreate it with the new column in the right place
Do you have a solution please?
Add column using SQL:
ALTER TABLE mydataset.mytable
ADD COLUMN new_column STRING;
Source: https://cloud.google.com/bigquery/docs/managing-table-schemas#sql
Change order of columns:
create or replace table <SCHEMA.NEW_TABLE_NAME> as
select col1,col2,col3 from <SCHEMA.OLD_TABLE_NAME>;
Source: Changing order of columns for a table
I am using sqlite3.
Suppose I have a view view_intermediate. I would like to create a temporary table from this view. In other words, turn the result of the view into a temporary table.
How should the SQL statement look like to do this?
SQLite supports CREATE TABLE AS..SELECT, so assuming you want the data in the table:
CREATE TABLE myTable AS
SELECT *
FROM view_intermediate;
If you want a table to be created from the view, but don't want the data, you can add a false condition.
CREATE TABLE myTable AS
SELECT *
FROM view_intermediate
WHERE 1=2;
I am trying to alter the column size of a view with the same command that we use for table like :
alter table
STUDENT
modify (
ROLL_NO VARCHAR2(80)
);
But its throwing error
SQL Error: ORA-00942: table or view does not exist
So how we can alter the column size of a view?
A view is simply saved query and "inherits" column type from underlying base table. So if you need to change metadata you should alter view definition:
ALTER VIEW view_students
AS
SELECT CAST(roll_no AS VARCHAR2(80)) AS roll_no,
...
FROM tab_students;
If you want to change data type to store longer strings, then you need to locate base table and alter it instead:
ALTER VIEW tab_students
MODIFY (ROLL_NO VARCHAR2(80));
Here is the procedure that I followed :
1- First find the base table for that view by running the following query
SELECT * FROM DBA_DEPENDENCIES
WHERE OWNER = '<scheman_name>'
AND NAME = '<view_name>'
AND TYPE = 'VIEW';
2- Above query will you a table where you will find the base table under the column name 'REFERENCED_NAME'.
3- Now Change the column size of that base table.
NOTE: The view can be made up of 1 or more than 1 tables, so you need to change the column size of all those base tables.