I'm trying to read from a certain table (READTABLE) using an account (ACCOUNTX). This account has read (select) privileges on table, READTABLE. I checked this using:
from syscat.tabauth
where grantee = CURRENT USER and (SELECTAUTH = \'Y\' OR SELECTAUTH = \'G\')
This returned among others, READTABLE.
However, executing a statement in which I have FROM READTABLE
I get the following error:
[DB2/AIX64] SQL0204N "ACCOUNTX.READTABLE is an undefined name. SQLSTATE=42704
Why does this table get ACCOUNTX pre-pended to it? Or is my privilege-check query wrong?
Each table in DB2 belongs to a schema. Therefore, a fully qualified table name consists of both the schema name and the table name, separated by a dot.
If, when referencing a table, you do not qualify it with a schema name explicitly, DB2 will take the value of the CURRENT SCHEMA
variable set in your session. By default CURRENT SCHEMA
is initialized with the value of your authorization ID (username).
Apparently, your table READTABLE
belongs to a schema different from ACCOUNTX
. If you don't have permissions to read the table, the error will be different.