Dynamic subpartition creation to a partitioned table with data - sql

I have a table like below
Create table t1(
X number,
Y number ,
Z varchar,
Createdatetime date);
Partition by range (createdatetime) interval (numtodsinterval(3,day));
Above table has 5 billion data already partitioned by createdatetime
Now the requirement is to add new column
There may be multiple entries for x,y combo. So the new column must have Y for recent x,y combo (based on creatdatetime) and N for old entries.
I created a column and populated data.
Now I need to subpartition the above range partition
.
Subpartition by list using new column
There will be two sub partitions Y,N based on new column under each date range partitions. How to achieve this dynamically. I tried writing a procedure which loops through the partitions and execute immediate alter table modify partition add subpartition. But I'm getting invalid partition name error .
Any other alternative approaches are also welcome

Related

Oracle SQL - Import data from non-partitioned (regular table) into an empty partitioned table using expdp/impdp

Oracle version - 12.2.0.1
OS version - 7.1 Exadata box.
I have a table with 5 million rows into a regular table (non-partitioned) and my client has created an empty structure of the above table (partitioned by date). Now, he wants to export(expdp) the data from original table (non-partitioned) and import (impdp) into the partitioned table and wants the data to go into the partitions accordingly. Is this achievable ?
Please let me know if this is achievable through any method ?
Thank you,
A normal datapump with TABLE_EXISTS_ACTION=APPEND will take care of it assuming the table has already been created in the target schema.
If you have a table that is already loaded and is unpartitioned, there is the 'alter table' option as mentioned, which lets you define the partitionined schema for both table and indexes, and do it online
SQL> alter table T modify
2 partition by range (object_id) interval (10000)
3 (
4 partition p1 values less than (20000)
5 ) online
6 update indexes
7 ( ix local,
8 ix2 global partition by range (created)
9 (
10 partition ix2_p1 values less than (date '2016-08-01'),
11 partition ix2_p2 values less than (maxvalue)
12 )
13 );
Table altered.
I'm confused, you use the tag oracle10g, but mention 12.2 in the question?
Yes, this will work, on two conditions:
It is clear into which partition each row will be sorted. Unless you use system partitioning (PARTITION BY SYSTEM), that should be fine.
All the necessary partitions do exist. Either your client uses interval partitions (for instance PARTITION BY RANGE (my_date) INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))), or they set up partitions to cover all dates in the unpartitioned table.

How can I alter a temporary table with 36 million rows to add a new column?

I am working with a temporary table in Netezza that contains the columns id, gender, start_date, and end_date. I want to add a new column to this table that contains a default date of 2019-01-01 for all rows. The table to which I want to add this column is a local temp table, so ALTER TABLE does not work ("Error: Operation not allowed on a temp table"). To get around this, I created a new temp table as follows:
DROP TABLE new_temp_table IF EXISTS;
GO
SELECT id, gender, start_date, end_date, '2019-01-01' default_date
INTO TEMP TABLE new_temp_table
FROM old_temp_table;
GO
This new table is limited to 1000 rows by the SELECT...INTO syntax. My old table has 36 million rows. Is there a solution that would allow me to directly modify the old table to add the new default date column, or some other way to get around the 1000-row limit with SELECT...INTO?

When is the feature of partitioning on integer column available in BIGQUERY table?

Do we know when google will enable partitioning on integer column in BIGQUERY table? And can we partition BIGQUERY table after it is created or it has to be partitioned at the same time when the BIGQUERY table is created?
Many thanks.
So called Integer range partitioned tables are available already as Beta in a pre-release state
Table must be set as partitioned during its creation as in example below
CREATE TABLE `project.dataset.table`
PARTITION BY RANGE_BUCKET(customer_id, GENERATE_ARRAY(0, 100, 10)) AS
SELECT 1 AS customer_id, DATE '2019-10-01' AS day
See more details in Creating and using integer range partitioned tables

Add new partition to already partitioned hive table

I have a partitioned table Student which already has one partition column dept. I need to add new partition column gender
Will it be possible to add this new partition column in already partitioned hive table.
The table data does not have gender column. It is a new constant column to be added in hive table.
Partitions are hierarchical folders like table_location/dept=Accounting/gender=male/
Folder structure should exist. You can easily add non-partition column as the last one and it will return NULLs if the data does not contain that column, but to add a partition column the easiest way is to create new table partitioned as you want, insert overwrite that table from the old one (selecting partitions columns as the last ones), drop old table, rename new one.
See this answer about dynamic partitions load: https://stackoverflow.com/a/48901871/2700344

Creating a table with date as range partition in SQL Server 2012

I am new to SQL Server coding. Please let me know how to create a table with range partition on date in SQL Server
A similar syntax in teradata would be the following (a table is created with order date as range partition over year 2012 with each day as single partition )
CREATE TABLE ORDER_DATA (
ORDER_NUM INTEGER NOT NULL
,CUST_NUM INTEGER
,ORDER_DATE DATE
,ORDER_TOT DECIMAL(10,2)
)
PRIMARY INDEX(ORDER_NUM)
PARTITION BY (RANGE_N ( ORDER_DATE BETWEEN DATE ‘2012-01-01’ AND DATE 2012-12-31 EACH INTERVAL ‘1’ DAY));
Thanks in advance
The process of creating partitioned table is described on MSDN as follows:
Creating a partitioned table or index typically happens in four parts:
1. Create a filegroup or filegroups and corresponding files that will hold the partitions specified by the partition scheme.
2. Create a partition function that maps the rows of a table or index into partitions based on the values of a specified column.
3. Create a partition scheme that maps the partitions of a partitioned table or index to the new filegroups.
4. Create or modify a table or index and specify the partition scheme as the storage location.
You can find code samples on MSDN.