Non nullable dummy column in Netezza View - view

How to create a non nullable dummy column in Netezza View. In the metadata of the view that column should show as notnull.
CREATE OR REPLACE VIEW [VIEW_NAME] AS
SELECT CAST('01/01/9999' AS DATE) EFFV_DT;
For the above statement the view is creating properly but the metadata of the EFFV_DT column is showing as NULLABLE. But i want that as NOT NULLABLE.
Thanks

Related

Unable to create table through another table in oracle SQL developer

I have been trying to create a new table by using below query :
"Create table d1_details_test2
as
select * from d1_details"
this above query gives me an error :
actually "d1_details" table has one column which has "Long" datatype and i cannot change it.
so i want to know the any other way to create the table.
Thanks
The long data type is subject to many restrictions. Create table as select is one of these.
You can get around it by applying to_lob in the select, which converts it to a clob:
create table views as
select view_name, text from user_views;
ORA-00997: illegal use of LONG datatype
create table views as
select view_name, to_lob ( text ) lob
from user_views;
desc views
Name Null? Type
VIEW_NAME VARCHAR2(128)
LOB CLOB

Object (Table, View ...) Status Metadata in Postgres

Is it possible to query object (object being table, view, etc.) status in Postgres? In Oracle an equivalent query would be:
SELECT owner,
object_name,
status
FROM all_objects
WHERE object_type = 'VIEW'
(returns VALID/INVALID in status column)
Please let me know. I've googled for this already, but have not found much.
Michael
https://stackoverflow.com/a/39120069/5315974
Postgres does not let you break the view (RULE), eg:
t=# create table so183 (i int);
CREATE TABLE
t=# create view v183 as select i from so183;
CREATE VIEW
t=# alter table so183 alter COLUMN i type text using i::text;
ERROR: cannot alter type of a column used by a view or rule
DETAIL: rule _RETURN on view v183 depends on column "i"

In hive, is there a way to specify between which columns to add a new column to?

I can do
ALTER TABLE table_name ADD COLUMNS (user_id BIGINT)
to add a new column to the end of my non-partition columns and before my partition columns.
Is there any way to add a new column to anywhere among my non-partition columns?
For example, I would like to put this new column user_id as the first column of my table
Yes it is possible to change the location of columns but only after adding it in the table using CHANGE COLUMN
In your case, first add the column user_id to the table with below command:
ALTER TABLE table_name ADD COLUMNS (user_id BIGINT);
Now to make user_id column as the first column in your table use change column with FIRST clause:
ALTER TABLE table_name CHANGE COLUMN user_id user_id BIGINT first;
This will move the user_id column to the first position.
Similarly you can use After instead of first if you want to move the specified column after any other column. Like say, I want to move dob column after user_id column. Then my command would be:
ALTER TABLE table_name CHANGE COLUMN dob dob date AFTER user_id;
Please note that this commands changes metadata only. If you are moving columns, the data must already match the new schema or you must change it to match by some other means.
Ah, here's the explanation for why you listed user_id twice (it's not a type):
// Next change column a1's name to a2, its data type to string, and put it after column b.
ALTER TABLE test_change CHANGE a1 a2 STRING AFTER b;
// The new table's structure is: b int, a2 string, c int.
No, it is not possible.
One solution is to create new table using "CREATE TABLE AS SELECT" approach and drop older one.

Add a column, with a default value, to an existing table in oracle

I created a table named- books and have a column in that by the title 'color' . Initially I have null values in the column 'color'. Now, when I run the following query :
alter table books modify color default 'blue';
schema is formed but on doing select *from books , all the values in column color are still null. What would be the correct query to fire?
here is the link:
http://sqlfiddle.com/#!4/f4210/1
Of course. Alter table just changes the table structure but not the content. New entries will get the default.
To update the existing values run a sql-update query like:
update books set color='blue' where colore is null;
If you now inserting into table then only will come with default values. This statement don't know about previous contents of this table. In non technical language, you are telling oracle to do so now on-wards. This statement will not perform check to old values.
alter is ok for the next values to be inserted: try to insert lines without specifying a value for column color, value should be blue.
But this does not work for existing values, for which you just need an update:
update books set color = 'blue';
Hi this query will be used to add column with default value in existing table in oracle.
alter table <table_name> add <column_name> <contraint> default <default_value> not null;
example:
alter table books add record_status number(1,0) default 1 not null;
alter table books add color varchar(20) default 'blue' not null;

Oracle: Is there a way to get the column data types for a view?

For a table in oracle, I can query "all_tab_columns" and get table column information, like the data type, precision, whether or not the column is nullable.
In SQL Developer or TOAD, you can click on a view in the GUI and it will spit out a list of the columns that the view returns and the same set of data (data type, precision, nullable, etc).
So my question is, is there a way to query this column definition for a view, the way you can for a table? How do the GUI tools do it?
You can use user_tab_columns (or all_tab_columns and dba_tab_columns respectively) regardless if table_name refers to a view or a table.
View columns appear in all_tab_columns, so you can query them just as you can tables.
Just simply write this query:
SQL> desc TABLE/VIEW NAME;
For example if the table/view name is "department" Then just write:
SQL> desc department;
This will give the list of all fields, it's type and default Null info of the table or view.
you can use the ANSI catalog views, should work for most RDBMs
select *
from information_schema.columns c
join information_schema.tables t on c.table_name = t.table_name
where table_type = 'view'

Resources