I want to remove partitioning from table:
ALTER TABLE rosing_watch_sessions REMOVE PARTITIONING
but it raise error:
Severity: ROLLBACK,
Message: Unsupported access to table with projection expressions or aggregates,
Sqlstate: 0A000,
Routine: checkUnsupportedMaVeriCKTableError,
File: /scratch_a/release/16125/vbuild/vertica/Catalog/CatalogLookup.cpp,
Line: 1383
What does it mean this error message?
P.S.
Result of select export_objects('', 'rosing_watch_sessions'):
CREATE TABLE staging.rosing_watch_sessions
(
id IDENTITY ,
session_uid varchar(255) NOT NULL,
...
)
PARTITION BY (rosing_watch_sessions.requested_day);
ALTER TABLE staging.rosing_watch_sessions ADD CONSTRAINT C_PRIMARY PRIMARY KEY (id);
CREATE PROJECTION staging.rosing_watch_sessions_super /*+basename(rosing_watch_sessions),createtype(P)*/
(
id,
session_uid,
...
)
AS
SELECT rosing_watch_sessions.id,
rosing_watch_sessions.session_uid,
...
FROM staging.rosing_watch_sessions
ORDER BY rosing_watch_sessions.id
SEGMENTED BY hash(rosing_watch_sessions.requested_day) ALL NODES ;
CREATE PROJECTION staging.channel_coverage
(
resource_uid,
device_uid,
request_date,
num_requests,
__partition_key_value__ ENCODING RLE
)
AS
SELECT rosing_watch_sessions.resource_uid,
rosing_watch_sessions.device_uid,
date("timezone"('UTC'::varchar(3), rosing_watch_sessions.requested_at)) AS request_date,
count(rosing_watch_sessions.session_uid) AS num_requests,
max(rosing_watch_sessions.requested_day) AS __partition_key_value__
FROM staging.rosing_watch_sessions
GROUP BY rosing_watch_sessions.resource_uid,
rosing_watch_sessions.device_uid,
date("timezone"('UTC'::varchar(3), rosing_watch_sessions.requested_at))
;
SELECT MARK_DESIGN_KSAFE(0);
Live aggregate projections do not support certain operations (yet).
DROP PROJECTION staging.channel_coverage;
ALTER TABLE rosing_watch_sessions REMOVE PARTITIONING;
Then rebuild staging.channel_coverage using the DDL you have.
Related
to execute the code : https://dbfiddle.uk/?rdbms=oracle_21&fiddle=69131953cf61459b64092025737d79b7
I have a object that has several field.
And I want to say that a field can have only certain values.
I tried to do that the same way I would do it with a table
create type oa as object(
a VARCHAR2(59) constraint cta check(a in ('a1','a2' ))
)
ORA-24344: success with compilation error
I have tried to create a table and say that my object has the same fields
CREATE TABLE ta(
a VARCHAR2(59) constraint cta check(a in ('a1','a2' ))
)
Create type oa2 as ta%rowtype
ORA-24344: success with compilation error
It doesn't work either.
You cannot; constraints can only be applied to tables or views.
From the constraint documentation:
Constraint clauses can appear in the following statements:
CREATE TABLE (see CREATE TABLE)
ALTER TABLE (see ALTER TABLE)
CREATE VIEW (see CREATE VIEW)
ALTER VIEW (see ALTER VIEW)
As an alternative, you can declare the type as:
CREATE TYPE oa as object(
a VARCHAR2(59)
);
Then declare an object-derived table with an added CHECK constraint:
CREATE TABLE oat OF oa (
CONSTRAINT oat_chk CHECK (a in ('a1', 'a2'))
);
Then:
INSERT INTO oat VALUES (oa('a1'));
INSERT INTO oat (a) VALUES ('a1');
works but:
INSERT INTO oat VALUES (oa('b1'));
INSERT INTO oat (a) VALUES ('b1');
Violates the check constraint.
db<>fiddle here
Below is the Tables i have created.
CREATE TYPE ft_obj AS OBJECT (
ftid NUMBER(5),
ftlocation VARCHAR(30),
country VARCHAR(10)
);
/
CREATE TABLE ft_table OF ft_obj (
ftid PRIMARY KEY
) OBJECT IDENTIFIER IS PRIMARY KEY;
/
CREATE TYPE frod_obj AS OBJECT (
prodid NUMBER(6),
ft_ref ft_obj,
proddesc VARCHAR(50),
costperitem DECIMAL,
labcostperitem DECIMAL
);
/
CREATE TABLE frod_table OF frod_obj (
prodid PRIMARY KEY
) OBJECT IDENTIFIER IS PRIMARY KEY;
CREATE TYPE wf_obj AS OBJECT (
wfid NUMBER,
ft_ref ft_obj,
wfname VARCHAR(30),
taxcode INT,
yearlyincome DECIMAL,
yearlytax DECIMAL
);
/
CREATE TABLE wf_table OF wf_obj (
wfid PRIMARY KEY
) OBJECT IDENTIFIER IS PRIMARY KEY;
/
CREATE TYPE wfusage_obj AS OBJECT (
jobdate DATE,
jobhours INT,
jobhourlyrate DECIMAL,
jobposted CHAR,
wfid_ref REF wf_obj
);
/
CREATE TYPE wfusage_nesttabtyp AS
TABLE OF wfusage_obj;
/
CREATE TABLE wfusage_objtab OF wfusage_obj;
/
CREATE TYPE odetails_obj AS OBJECT (
mfid NUMBER,
prodid_ref REF frod_obj,
quantity INT,
itemprice DECIMAL,
wfusage_ntab wfusage_nesttabtyp
);
/
CREATE TYPE odetails_nesttabtyp AS
TABLE OF odetails_obj;
/
CREATE TYPE prod_obj AS OBJECT (
prodoid NUMBER,
odate DATE,
promisedate DATE,
completiondate DATE,
shipmentdate DATE,
status VARCHAR(20),
odetails_ntab odetails_nesttabtyp
);
/
CREATE TABLE prod_objtab OF prod_obj (
PRIMARY KEY ( prodoid )
) OBJECT IDENTIFIER IS PRIMARY KEY
NESTED TABLE odetails_ntab STORE AS oprod_ntab ( (
PRIMARY KEY ( nested_table_id,
mfid )
)
ORGANIZATION INDEX
COMPRESS ) RETURN AS LOCATOR
/
ALTER TABLE oprod_ntab ADD (
SCOPE FOR ( prodid_ref ) IS frod_table
);
/
Getting the below error while creating Nested Table.
ORA-02320: failure in creating storage table for nested table column
odetails_ntab ORA-25175: no PRIMARY KEY constraint found
02320. 00000 - "failure in creating storage table for nested table column %s"
*Cause: An error occurred while creating the storage table for the
specified nested table column.
*Action: See the messages that follow for more details. If the situation
they describe can be corrected, do so; otherwise contact Oracle
Support.
INSERT INTO prod_objtab VALUES ( 45000,
'12-April-2019',
'01-MAy-2019',
'01-MAy-2019',
'01-MAy-2019',
'COMPLETED',
odetails_nesttabtyp()
);
INSERT INTO TABLE (SELECT pr.odetails_ntab FROM prod_objtab pr WHERE pr.prodorderid = 45000 )
values (45001,(SELECT REF(pt) FROM frod_table pt WHERE pt.prodid = 10001 ),100,500,
wfusage_nesttabtyp(wfusage_obj('12-April-2019',60,100,'AME',
(SELECT REF(wf) FROM wf_table wf WHERE wf.wfid = 240))));
getting the error in line 9
ORA-01401: inserted value too large for column
ORA-02320: failure in creating storage table for nested table column
odetails_ntab ORA-25175: no PRIMARY KEY constraint found 02320. 00000
- "failure in creating storage table for nested table column %s" *Cause: An error occurred while creating the storage table for the specified nested table column. *Action: See the messages that follow
for more details. If the situation they describe can be corrected, do
so; otherwise contact Oracle Support.
Since you have done Multi-level nesting, while creating the table you need 2 levels of Storage as well for the Nested tables. See below how you can do it.
CREATE TABLE prod_objtab OF prod_obj (
PRIMARY KEY ( prodoid )
) OBJECT IDENTIFIER IS PRIMARY KEY
NESTED TABLE odetails_ntab STORE AS oprod_ntab ( ( PRIMARY KEY (NESTED_TABLE_ID, mfid ))
ORGANIZATION INDEX COMPRESS
NESTED TABLE wfusage_ntab STORE AS XX ) RETURN AS LOCATOR;
Read more at
https://docs.oracle.com/en/database/oracle/oracle-database/18/adobj/multilevel-collection-types.html#GUID-76D5A6B0-28AD-483D-942C-B7F3B90AC379
I have created table with a partition:
CREATE TABLE edw_src.pageviewlog_dev
(
accessurl character varying(1000),
msisdn character varying(1000),
customerid integer
)
WITH (
OIDS=FALSE
)
DISTRIBUTED BY (msisdn)
PARTITION BY RANGE(customerid)
(
PARTITION customerid START (0) END (200)
)
Now I want to change the datasize of accessurl from 1000 to 3000.I am not able to change the datasize,Whenever I am trying I am getting the error.
ERROR: "pageviewlog_dev_1_prt_customerid" is a member of a partitioning configurationHINT: Perform the operation on the master table.
I am able to change If I change the datatype from pg_attribute.If there any other way to change the datasize of existing column other than pg_attribute
I have found the Solution for the same .Sorry for the replying late .Below is the way to do ,whenever we face this kind of problem in "Post grel and greenplum"
UPDATE pg_attribute SET atttypmod = 300+4
WHERE attrelid = 'edw_src.ivs_hourly_applog_events'::regclass
AND attname = 'adtransactionid';
Greenplum isn't Postgresql so please don't confuse people by asking a Greenplum question with PostgreSQL in the title.
Don't modify catalog objects like pg_attribute. That will cause lots of problems and isn't supported.
The Admin Guide has the syntax for changing column datatypes and this is all you need to do:
ALTER TABLE edw_src.pageviewlog_dev
ALTER COLUMN accessurl TYPE character varying(3000);
Here is the working example with your table:
CREATE SCHEMA edw_src;
CREATE TABLE edw_src.pageviewlog_dev
(
accessurl character varying(1000),
msisdn character varying(1000),
customerid integer
)
WITH (
OIDS=FALSE
)
DISTRIBUTED BY (msisdn)
PARTITION BY RANGE(customerid)
(
PARTITION customerid START (0) END (200)
);
Output:
NOTICE: CREATE TABLE will create partition "pageviewlog_dev_1_prt_customerid" for table "pageviewlog_dev"
Query returned successfully with no result in 47 ms.
And now alter the table:
ALTER TABLE edw_src.pageviewlog_dev
ALTER COLUMN accessurl TYPE character varying(3000);
Output:
Query returned successfully with no result in 62 ms.
Proof in psql:
\d edw_src.pageviewlog_dev
Table "edw_src.pageviewlog_dev"
Column | Type | Modifiers
------------+-------------------------+-----------
accessurl | character varying(3000) |
msisdn | character varying(1000) |
customerid | integer |
Number of child tables: 1 (Use \d+ to list them.)
Distributed by: (msisdn)
If you are unable to alter the table it is probably because the catalog is corrupted after you updated pg_attribute directly. You can try dropping the table and recreating it or you can open a support ticket to have them attempt to correct the catalog corruption.
I've already tried out a tool named TOYS. I found it free but unfortunately it didn't work.
Then, I tried "RED-Gate Schema Compare for Oracle" but it uses the technique to drop and recreate the table mean while I need to just alter the table with the newly added/dropped columns.
Any help is highly appreciated
Thanks
Starting from Oracle 11g you could use dbms_metadata_diff package and specifically compare_alter() function to compare metadata of two schema objects:
Schema #1 HR
create table tb_test(
col number
)
Schema #2 HR2
create table tb_test(
col_1 number
)
select dbms_metadata_diff.compare_alter( 'TABLE' -- schema object type
, 'TB_TEST' -- object name
, 'TB_TEST' -- object name
, 'HR' -- by default current schema
, 'HR2'
) as res
from dual;
Result:
RES
-------------------------------------------------
ALTER TABLE "HR"."TB_TEST" ADD ("COL_1" NUMBER);
ALTER TABLE "HR"."TB_TEST" DROP ("COL");
I create a table in Oracle 11g with the default value for one of the columns. Syntax is:
create table xyz(emp number,ename varchar2(100),salary number default 0);
This created successfully. For some reasons I need to create another table with same old table structure and data. So I created a new table with name abc as
create table abc as select * from xyz.
Here "abc" created successfully with same structure and data as old table xyz. But for the column "salary" in old table "xyz" default value was set to "0". But in the newly created table "abc" the default value is not set.
This is all in Oracle 11g. Please tell me the reason why the default value was not set and how we can set this using select statement.
You can specify the constraints and defaults in a CREATE TABLE AS SELECT, but the syntax is as follows
create table t1 (id number default 1 not null);
insert into t1 (id) values (2);
create table t2 (id default 1 not null)
as select * from t1;
That is, it won't inherit the constraints from the source table/select. Only the data type (length/precision/scale) is determined by the select.
The reason is that CTAS (Create table as select) does not copy any metadata from the source to the target table, namely
no primary key
no foreign keys
no grants
no indexes
...
To achieve what you want, I'd either
use dbms_metadata.get_ddl to get the complete table structure, replace the table name with the new name, execute this statement, and do an INSERT afterward to copy the data
or keep using CTAS, extract the not null constraints for the source table from user_constraints and add them to the target table afterwards
You will need to alter table abc modify (salary default 0);
new table inherits only "not null" constraint and no other constraint.
Thus you can alter the table after creating it with "create table as" command
or you can define all constraint that you need by following the
create table t1 (id number default 1 not null);
insert into t1 (id) values (2);
create table t2 as select * from t1;
This will create table t2 with not null constraint.
But for some other constraint except "not null" you should use the following syntax
create table t1 (id number default 1 unique);
insert into t1 (id) values (2);
create table t2 (id default 1 unique)
as select * from t1;