How to copy a Specific Partitioned Table - postgresql

I would like to shift data from a specific paritioned table of parent to separate table.Can someone suggest what's the better way.
If I create a table
CREATE TABLE parent columns(a,b,c)partition by c
c Type is DATE.
CREATE TABLE dec_partition PARTITION OF parent FOR VALUES FROM '2021-02-12' to 2021-03-12;
Now I want to copy table dec_partition to separate table in single command with least time.
NOTE: The table has around 4million rows with 20 columns (1 of the column is in jsonb)

Related

What is the most efficient way to create a table B identical to table A but with different column ordering?

I have a PG table A with columns (x,y,z), now I needed and added a BIGSERIAL id to it but then A ends being like A(x,y,z,id) and I would rather have the columns in the following order: A(id,x,y,z).
I know the only way to accomplish this, is by copying A into a new temporary table B with the desired order, then drop A and rename B to A. I would use CREATE TABLE B AS SELECT ... FROM A ... but do I get all the same indexes and constraints as in A? what's the most streamlined simplest way to do this?

Is it possible, when i save a data in postgresql table, automatically, id of record save in another table without trigger

I have 2 tables. First table is called Person. Second table is called PersonRule. Person table has much columns. But PersonRule has just 2 columns. In the person table, there is a column called ruleid. The column at the same time, there is in the PersonRule table. Is it possible, when i insert to data Person table, i want to automatically create a record in PersonRule table without trigger.?
And in PostgreSQL how can i do this.?

Db2 zos update set of values in tables

There are set of values to update. Example: table t1 has column c1 which has to be updated from 1 to x. There are around 300 such sets available in a file and around 15 such tables with over 100k of records.
What is the optimal way of doing this?
Approaches I can think of are:
individual update statement for old with new value in all tables
programmatically read the file and create dynamic update statement
using merge into table syntax
In one of the tables the column is primary key with tables referencing them as foreign key

PostgreSQL - Dynamic addition of large no of columns

Assume I have a table named tracker with columns (issue_id,ingest_date,verb,priority)
I would like to add 50 columns to this table.
Columns being (string_ch_01,string_ch_02,.....,string_ch_50) of datatype varchar.
Is there any better way to add columns with single procedure rather than executing the following alter command 50 times?
ALTER TABLE tracker ADD COLUMN string_ch_01 varchar(1020);
Yes, a better way is to issue a single ALTER TABLE with all the columns at once:
ALTER TABLE tracker
ADD COLUMN string_ch_01 varchar(1020),
ADD COLUMN string_ch_02 varchar(1020),
...
ADD COLUMN string_ch_50 varchar(1020)
;
It's especially better when there are DEFAULT non-null clauses for the new columns, since each of them would rewrite the entire table, as opposed to rewriting it only once if they're grouped in a single ALTER TABLE.

Hive partitioning external table based on range

I want to partition an external table in hive based on range of numbers. Say numbers with 1 to 100 go to one partition. Is it possible to do this in hive?
I am assuming here that you have a table with some records from which you want to load data to an external table which is partitioned by some field say RANGEOFNUMS.
Now, suppose we have a table called testtable with columns name and value. The contents are like
India,1
India,2
India,3
India,3
India,4
India,10
India,11
India,12
India,13
India,14
Now, suppose we have a external table called testext with some columns along with a partition column say, RANGEOFNUMS.
Now you can do one thing,
insert into table testext partition(rangeofnums="your value")
select * from testtable where value>=1 and value<=5;
This way all records from the testtable having value 1 to 5 will come into one partition of the external table.
The scenario is my assumption only. Please comment if this is not the scenario you have.
Achyut