Weird error: relation <schema name> does not exist - sql

I am running a DDL statement like this in Postgres 11
ALTER SEQUENCE kwt.VisitReport_seq OWNED BY kwt.VisitReport;
I am running it as DBADMIN.
Yet I get some weird error:
SQL Error [42P01]: ERROR: relation "kwt" does not exist
ERROR: relation "kwt" does not exist
ERROR: relation "kwt" does not exist
But this is strange... kwt is not a relation, it is a schema.
What is going on?!

As often happens right after posting here I found the problem.
The statement should be:
ALTER SEQUENCE kwt.VisitReport_seq OWNED BY kwt.VisitReport.ID;
i.e. it should refer (of course) to the column name, not to the table name.

Related

How to truncate table that my user owns in Oracle without error message

Thanks for reading this post. I am running into a strange issue in Oracle 10g. I am trying to figure out how to truncate a table without errors being generated.
What I need to do:
truncate a table that my user owns
truncate table EXAMPLE_USER.EXAMPLE_TABLE;
What is happening: rows within the table are successfully removed, but the following error is generated:
Error starting at line 1 in command:
truncate table EXAMPLE_USER.EXAMPLE_TABLE
Error report:
SQL Error: ORA-00604: error occurred at recursive SQL level 1
ORA-00942: table or view does not exist
ORA-06512: at line 50
00604. 00000 - "error occurred at recursive SQL level %s"
*Cause: An error occurred while processing a recursive SQL statement
(a statement applying to internal dictionary tables).
*Action: If the situation described in the next error on the stack
can be corrected, do so; otherwise contact Oracle Support.
What I have already done:
Ensure that EXAMPLE_USER has the "drop any table" privilege
Make sure that the rows are removed after truncate statement is ran
Additional Info:
I cannot simply drop and re-create the table because the truncation happens as part of a large database upgrade/update script which is out of my control.
The error is leading me to believe that the truncate statement within Oracle uses some sort of sys package or procedure that my user does not have privilege to access or use, based on the "at line 50" portion of the message. The actual truncate statement itself is a single line script. Does anyone have experience with this issue in Oracle?
Regards,
Dave

Trying to add column of CLOB type to table in DB2

I need to add a column of type "CLOB" to the existing table in the database, so I am using the below query:
alter table foldet add("FOLDER_FIELD_VALUE_TWO" CLOB);
but I am getting the below error
Error starting at line : 5 in command -
alter table foldet add("FOLDER_FIELD_VALUE_TWO" CLOB)
Error report -
SQL Error: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=CLOB;DER_FIELD_VALUE_TWO";JOIN , DRIVER=3.63.75
How to add a column to the table?
You don't say what DB2 version or platform sends the error response, but the SQLSTATE/SQLCODE values should be consistent across essentially all of them. Looking up SQLSTATE 42501 in DB2 for i 7.2, the given reason is:
The authorization ID does not have the privilege to perform the
specified operation on the identified object.
IOW, you don't have sufficient authority to change the structure of the table when you connect with the userid that received the error.
SQLSTATE 42501 is from you latest comment. From your question, SQLSTATE 42601 is:
A character, token, or clause is invalid or missing.
Your comment describes how you cleared that up, and the answer from #SimeonVanov correctly addresses that.
ALTER TABLE table_name
ADD column_name datatype
This is the syntax for adding column to a table. So if you get rid of the brackets I think it should be ok.
You're getting the error (-551) because you don't have the ALTER authority on the table. It's all there in the error message, as shown in the manual.
SQL Error: SQLCODE=-551, SQLSTATE=42501, SQLERRMC=IPASS;ALTER TABLE;FOLDET, DRIVER=3.63.75
^^^^ ^^^ ^^^^^^^^^^ ^^^
error code user privilege table

For a read only user why do DROP and INSERT fail with different errors

I have a database user with read only permissions for table example_table.
Select * from example_table;
Works fine.
insert into example_table values('example');
Fails as expected. "insufficient privileges"
drop table example_table;
Fails with error message "table or view does not exist"
My question is. Why do the last two examples not both fail with "insufficient privileges" why when used in the ddl statement can it not even see the table?
Oracle 10g
Thank you.
Your SELECT would fail without a synonym, so you're not selecting directly from the table, but through a synonym.
DROP TABLE is DDL, and synonyms can't be used in most DDL statements. So in your case the statement goes after a real object (by default in the current schema if you have not specified an owner), doesn't find any object by that name, hence the (admittedly unhelpful) error message.
If instead you had written:
drop table owner.example_table;
Then you would have received the expected error message.

Postgres: Inserting rows into table with foreign key

I have a table with a foreign key type which links to table wp_types. Whenever I try and insert a row into that table I get the error:
ERROR: permission denied for schema base
LINE 1: SELECT 1 FROM ONLY "base"."wp_types" x WHERE "id" OPERATOR(p...
^
QUERY: SELECT 1 FROM ONLY "base"."wp_types" x WHERE "id" OPERATOR(pg_catalog.=) $1 FOR SHARE OF x
The query is being executed as postgres.
Also I do not understand what this query is trying to do, it is clearly linked with checking the foreign key constraints but I don't understand how.
From postgresql docs:
If ONLY is specified, only that table is scanned. If ONLY is not specified, the table and all its descendant tables (if any) are scanned.
As you mentioned error is connected with checking foreign keys. When ONLY is specified postgres can not check them and it may cause an error.
Two points:
Is it possible you dropped the superuser permissions from the postgres user?
What are the permissions for the base schema?
Now one thing to consider is that you aren't sure what the query is doing. A simple EXPLAIN can show you what it is doing, but the error suggests the problem is with schema permissions, not with what the query is doing.
Try:
GRANT USAGE ON SCHEMA base TO postgres;

How to deal with a Firebird table that's apparently both there and not there

I've just had something very strange happen to me with a Firebird database.
I was trying to create a table, and the CREATE TABLE failed for some reason. But now it's stuck in a very strange state:
If I try to CREATE TABLE again with the same table name, it gives an error: the table already exists. But if I try to DROP TABLE that table, it gives an error: the table does not exist. Trying to SELECT * FROM that table gives the "table does not exist" error, and the name does not show up in the metadata query:
SELECT RDB$RELATION_NAME
FROM RDB$RELATIONS
WHERE RDB$SYSTEM_FLAG=0
So for some reason, the table really seems to not be there, but I can't create it because something somewhere indicates that it does exist.
Does anyone have any idea how to fix this? I've already tried closing all connections to that database, which has helped with inconsistency issues in the past, but this time it doesn't help.
You didn't give details about what was the error when you tried to create the table, so I cannot comment it. But RDB$RELATIONS is not the only system table affected when you create a table. Maybe you are now in an inconsistent situation where some information about that table exists in some system tables and doesn't exists in others.
Another option is corrupted indexes in the system tables, so the record is not there but the index think it still exists.
Try to do a backup/restore and see if it helps. It it doesnt work, try to search for records related to that "non created" table in the other system tables (RDB$RELATION_FIELDS, etc) and if you find any, try to delete them.
As a last option, you may create a new clean database with correct metadata and pump your data to it using IBDataPump.