SQL Error [42P07]: ERROR: relation "table1" already exist - amazon-redshift

Running a query to create a table, in the framework DBeaver v22, the error returns from a random table, every time I run the SQL script and it hits a query to create a table.
The script has a few thousands of lines, lots of drops and creates tables and. the very same error happens randomly when a CREATE query gets executed.
At the time I created this thread, I executed the script and it returned error in the creation of table1.
But It could have been any other. It doesn`t seem to be an error in he syntax/grammar of my SQL, but somehow in the engine of DBeaver 22.2. Because the error returns in a random table as per script execution.
SQL Error [42P07]: ERROR: relation "table1" already exist
Even though I added the following query to DROP TABLE, right before the one to CREATE table, the error still returns, when the query to create gets executed.
DROP TABLE IF EXISTS sandbox.table1;
CREATE TABLE sandbox.table1 as ();
I wonder if it takes a long time to drop the table so that, the create command line returns error
Is that possible to be the cause ?
Do I need a timer to wait for RDBMS fully drop the table?
SQL Error [42P07]: ERROR: relation "table1" already exist

Accessing further logs I`ve identified the root cause was permission error.
As It couldn't delete then creating table caused the error
org.jkiss.dbeaver.model
Error
Wed Dec 07 11:38:44 BRT 2022
SQL Error [42501]: ERROR: permission denied for relation table1

Related

truncate table. Error Msg = sqlcode -668 sqlerrmc=7

I am trying to run this DB2 query on DBEAVER:
TRUNCATE table departments immediate
but I got this error:
DB2 SQL Error: SQLCODE=-668, SQLSTATE=57016, SQLERRMC=7;DB2INST1.DEPARTMENTS, DRIVER=4.19.49
(it is happening just when I run it on DBEVAER (external channel) on local it's run well.
help someone?
The sqlcode -668 with sqlerrmc=7 (this 7 is the "reason code") means:
SQL0668N Operation not allowed for reason code "" on
table
"".
and the reason code 7 means:
The table is in the reorg pending state. This can occur after an
ALTER TABLE statement containing a REORG-recommended operation.
If your userid has the correct permissions, then try:
reorg table db2inst1.departments
if you have command-line access to Db2, or from jdbc application like DBeaver call admin_cmd ('reorg table db2inst1.departments').
But the reorg will fail if your account lacks permissions, or if the syntax is not allowed on your Db2-server version, and in that case you must ask a DBA to do the work for you, or a become user db2inst1 and run the reorg.
When the reorg completes without errors, retry the truncate table.

Db2 doesn't allow to update table, throws an error saying that operation is incomplete

I'm getting an error when trying to update a table. The SQL statement is:
UPDATE dda_accounts SET TYPE_SK = TYPE_SK - 10 WHERE TYPE_SK > 9;
The error I get is:
SQL Error [57007]: Operation not allowed for reason code "7" on table
"BANK_0002_TEST.DDA_ACCOUNTS".. SQLCODE=-668, SQLSTATE=57007, DRIVER=4.27.25
SQLSTATE 57007 says that there's something incomplete after an ALTER TABLE was executed.
I found this resolution, but it's not clear if it can be fixed or the only way to recover the table is using a backup.
Running a select statement works, only the update fails. What is the way to fix this table?
You need to REORG the table to recover, see this page for details.
When you get an error like this, lookup the SQL066N code with the reason code "7".
This shows:
The table is in the reorg pending state. This can occur after an ALTER
TABLE tatement containing a REORG-recommended operation.
Be aware the the previous alter table (that put the table into this state of reorg needed) might have happened quite some time ago, possibly without your knowledge.
If you lack the authorisation to perform reorg table inplace "BANK_0002_TEST.DDA_ACCOUNTS" , then contact your DBA for assistance. The DBA may choose to also reorg indexes at the same time, and to perform runstats (docs) on the table following completion of the reorg, and to check whether anything else needs rebinding.

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.

How to set table to LOGGED in postgresql 9.2?

I'm using PostgreSQL 9.2. I created a bunch of UNLOGGED tables, loaded data into there, and created primary keys. Now I'd like to set them back to LOGGED status.
I tried the command:
ALTER TABLE table_name SET LOGGED;
However, I get this error:
ERROR: syntax error at or near "LOGGED"
What is the proper syntax for this?

Postgres pg_dump now stored procedure fails because of boolean

I have a stored procedure that has started to fail for no reason. Well there must be one but I can't find it!
This is the process I have followed a number of times before with no problem.
The source server works fine!
I am doing a pg_dump of the database on source server and imported it onto another server - This is fine I can see all the data and do updates.
Then I run a stored procedure on the imported database that does the following on the database which has 2 identical schema's -
For each table in schema1
Truncate table in schema2
INSERT INTO schema2."table" SELECT * FROM schema1."table" WHERE "Status" in ('A','N');
Next
However this gives me an error now when it did not before -
The error is
*** Error ***
ERROR: column "HBA" is of type boolean but expression is of type integer
SQL state: 42804
Hint: You will need to rewrite or cast the expression.
Why am I getting this - The only difference between the last time I followed this procedure and this time is that the table in question now has an extra column added to it so the "HBA" boolean column is not the last field. But then why would it work in original database!
I have tried removing all data, dropping and rebuilding table these all fail.
However if I drop column and adding it back in if works - Is there something about Boolean fields that mean they need to be the last field!
Any help greatly apprieciated.
Using Postgres 9.1
The problem here - tables in different schemas were having different column order.
If you do not explicitly specify column list and order in INSERT INTO table(...) or use SELECT * - you are relying on the column order of the table (and now you see why it is a bad thing).
You were trying to do something like
INSERT INTO schema2.table1(id, bool_column, int_column) -- based on the order of columns in schema2.table1
select id, int_column, bool_column -- based on the order of columns in schema1.table1
from schema1.table1;
And such query caused cast error because column type missmatch.