Convert DB2 into Postgresql - postgresql

I am getting error when try to run the query with Postgres
ALTER TABLE EMP.USER DETACH PARTITION ID_CUST_111111 INTO DATA_PRTTN.ID_CUST_111111_USER
Wrapped by: java.sql.SQLException: SQL: ERROR: syntax error at or near "INTO"

You don't place a partition in a table in PostgreSQL. A partition already is a table. So simply remove the INTO table_name from the statement. You can rename the partition after detaching, but I don't see much sense in that.

Related

Deadlock detected on Alter table add column is postgresql

I am trying to add a column through Hasura cloud.
Running the SQL
alter table "public"."clinic_rosters" add column "with_user_id" uuid null default '';
But it is giving
SQL EXECUTION FAILED, DEADLOCK DETECTED.
Please help somebody how can I add column avoiding the deadlock error.

Is it possible to create partitioned table with 'create table as' in PostgreSQL?

I am trying to create a partitioned table as follows:
create table archive.table1
as table work1.table1 with no data
partition by range (wk_date)
and I am getting the following error:
SQL Error [42601]: ERROR: syntax error at or near "partition"
Position: 98
You can run the following, which is simpler and will work:
CREATE TABLE archive.table1 (LIKE work1.table1) PARTITION BY RANGE (wk_date);
No, this is not possible.
You need to first create the partitioned table, then you need to create the partitions. Once that is done you can do an insert into partitioned_table select * from old_table

PostreSQL error relation already exists while creating a partition

I created a partition (programmatically with Java, JPA/native query), after that I deleted it manually pgAdmin with DROP table my_partition. After that, I'm trying to re-create it again programmatically, but I get this error
SQL Error: 0, SQLState: 42P07
ERROR: relation "partition_2020_12_08" already exists
CREATE TABLE "myschema.com".partition_2020_12_08 PARTITION OF "myschema.com".measurement FOR VALUES FROM (1607385600000) TO (1607471999999)
Interesting that when I execute that SQL with pgAdmin, it works fine. It looks to me that PostreSQL caches some information when I'm using it with JDBC/Java driver.
How to debug this issue? I need to have a possibility to re-create the same partitions if needed.

Partition table created using 'CREATE TABLE AS'

How do we partition a table created using the CREATE TABLE AS command in PostgreSQL. I tried the following:
CREATE TABLE schema.table2 AS TABLE schema.table1 PARTITION BY LIST(col1)
but it gives this error:
ERROR: syntax error at or near "PARTITION"
That's not possible.
CREATE TABLE AS is different from CREATE TABLE and only supports a subset of features for the latter.

DB2 SQL Error: SQLCODE=-911, SQLSTATE=40001, SQLERRMC=68

I am getting this error when I ran:
alter table tablename add column columnname varchar(1) default 'N';
DB2 SQL Error: SQLCODE=-911, SQLSTATE=40001, SQLERRMC=68
How to solve it?
The alter statement wants to get an X lock on this row in SYSIBM.SYSTABLES. There is an open transaction that has this row/index value in an incompatible lock state. This lock that caused the timeout could even be from an open cursor that reads this row with an RS or RR isolation level.
Terminate any other SQL currently trying to query SYSTABLES and any utilities that may be trying to update SYSTABLES like reorg and runstats then try the alter again.
See DB2 Info center (I picked the one for DB2 10, most likely this error code is the same in other versions, but doublecheck!).
Seems there is a transaction open on your table, that prevents your alter command from execution.
after you have Altered a table you need to Reorg: reade up on it here:
Run the runstats script, which is a DB2 script, at regular intervals and set the script to gather RUNSTATS WITH DISTRIBUTION AND DETAILED INDEXES ALL.
In addition to running the runstats scripts regularly, you can perform the following tasks to avoid the problem:
Use REOPT ONCE or REOPT ALWAYS with the command-line interface (CLI ) packages to change the query optimization behavior.
In the DB2 database, change the table to make it volatile. Volatile tables indicate to the DB2 optimizer that the table cardinality can change significantly at run time (from empty to large and vice versa). Therefore, DB2 uses an index to access a table rather than a table scan.