SQLCODE=-104, SQLSTATE=42601, SQLERRMC=table;reorg ;JOIN <joined_table> - db2

when running this query on db2 on DBeaver :
reorg table departments
i got this error (just on external channel):
DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=table;reorg ;JOIN <joined_table>, DRIVER=4.19.49
what does this query mean?
how can I fix the error?
appricicate any help.

Try call sysproc.admin_cmd('reorg table db2inst1.departments')
as you are using DBeaver which is a jdbc application.
If you do not qualify the table name (for example, with db2inst1) then Db2 will assume that the qualifier (schema name) is the same as the userid name you used when connecting to the database.
DBeaver runs SQL statements, but it cannot directly run commands of Db2 - instead, any jdbc app can run Db2-commands indirectly via a stored-procedure that you CALL. The CALL is an SQL statement.
The reorg table is a command, it is not an SQL statement, so it needs to be run via the admin_cmd stored-procedure, or it can be run from the operating system command line (or db2 clp) after connecting.
So if you have db2cmd.exe on MS-Windows, or bash on linux/unix, you can connect to the database, and run commands via the db2 command.

Related

How to create multiple databases with Postgres in pgAdmin4

I am trying to run the following query in pgAdmin:
CREATE DATABASE abc;
CREATE DATABASE xyz;
And I get the following error:
ERROR: current transaction is aborted, commands ignored until end of transaction block
SQL state: 25P02
I'm relatively new to postgres.
With SQL Server it's possible to create multiple databases in a single query with the "GO" statement in between if necessary.
I've tried to google this error, and most answers are to simply run each line separately.
That would work, but I'm curious why this doesn't work.
It may also be a setting in pgAdmin.
The "autocommit" is currently on. I've tried it off, and same result.
I'm using postgres 14.5 (in aws)

run \dt in oracle sqldeveloper for PostgreSQL

I configured PostgreSQL for Oracle SQL developer.
I just tried to run the command \dt; from the worksheet and received below error
Error starting at line : 1 in command -
\dt
Error report -
SQL Error: ERROR: syntax error at or near "\"
Position: 1
Could you please advise how to run the commonly used psql commands from worksheet in Oracle SQL developer.
Edit1:
Are there any alternative equivalent for such psql command for oracle sql developer please. Thanks.
Doesn't SQL Developer offer a GUI view that provides the same info as \dt does? That is its job, afterall, and the point of using a GUI.
You can start psql with the -E option, then it will show you the SQL it executes to get the data behind the various backslash commands. You can then capture and run those queries in something else, like (presumably, I haven't tried it) SQL Developer.
You cannot do that.
psql commands are only available in psql.
Consider using psql, it is superior.

dBeaver (CE): DB2 LUW Connection with SQL ERROR 42704. Table Schema won't open but able to write SQL queries

After about a year and half, I am finally able to connect to the DB2 database we have through dBeaver. The connection is successful as a LUW (Our db2 is z/os). I was able to get the drivers required after installing IBM Data Studio.
Once I am connected, I go down the schema, get to Tables, and on clicking that, I get the below error.
SQL Error [42704]: SYSCAT.SCHEMATA IS AN UNDEFINED NAME. SQLCODE=-204, SQLSTATE=42704, DRIVER=3.69.56
SYSCAT.SCHEMATA IS AN UNDEFINED NAME. SQLCODE=-204, SQLSTATE=42704, DRIVER=3.69.56
THE DESCRIBE STATEMENT DOES NOT SPECIFY A PREPARED STATEMENT. SQLCODE=-516, SQLSTATE=26501, DRIVER=3.69.56
THE CURSOR SQL_CURLH200C1 IS NOT IN A PREPARED STATE. SQLCODE=-514, SQLSTATE=26501, DRIVER=3.69.56
SQL Error [42704]: SYSCAT.SCHEMATA IS AN UNDEFINED NAME. SQLCODE=-204, SQLSTATE=42704, DRIVER=3.69.56
However, if ignore the error and go to New SQL query and write a simple
Select * from schema.table
it works fine and get the results I want.
Considering the time i have spent to get till here, this is sufficient, but to deploy as a solution in my department, I need to be able to look at a Table List (schema).
Any help would be awesome.
EDIT1: What the issue is here, is that there is no SCHEMA with the name SYSCAT and no table named SCHEMATA.
The z/OS Db2 catalog has different names than the ones used on Db2 on distributed (Linux Unix Windows aka LUW). Here is a list of objects on Db2 z/OS that you can review.
It looks like you are using dBeaver to navigate through a UI the objects on Db2 for z/OS. You will need to ensure you have a db2 jcc driver that is for z/OS Db2. It looks like you may be using one from LUW as the SYSCAT.SCHEMATA is an LUW object, not a z/OS object.
Your other query works because you are specifying a known table name. Other queries should be fine. The issue is the interface in dbeaver is looking at Db2 system objects for LUW and not z/OS. This will continue until you are able to resolve the driver issue.
The IBM Data Server Drivers also require server sided set-up. Please see this information https://www.ibm.com/support/knowledgecenter/SSEPEK_12.0.0/java/src/tpc/imjcc_jccenablespsandtables.html
In DBeaver, when you create a connection choose the "DB2 z/OS driver" option under the Db2 drop down, when connecting to DB2 for z/OS
BTW DBeaver can shell share with Data Studio, so you can (if you wish) use both products in one install. No guarantees that they share happily in all cases, but it appears to work reasonably well.

Tomcat 8 Db2 Error: com.ibm.db2.jcc.b.eo: DB2 SQL Error: SQLCODE=-551, SQLSTATE=42501, SQLERRMC=M25044

I have been trying to resolve this error which was working for so long
out of nowhere we have started facing this issue.
My application, which is a plain Java web application (Jsp/Servlets and couple of utilities and control classes) running on Tomcat 8
One of the functionality is, the user keys in an id which is a key for a DB query to fire up the Database and get the results
In doing so I get this below error, which is more or less a symptom of user not having the privilege to execute the query on the
Db2 Database table.
When I am trying out the same query from any kind of Db2 Client tools or SQL prompt, I don't get this error at all:
" com.ibm.db2.jcc.b.eo: DB2 SQL Error: SQLCODE=-551, SQLSTATE=42501, SQLERRMC=M25044"
SQLCODE -551 means that the User executing the Query does not have the right Privilege. So find out which User is running the Query and grant the Privilege to that User. May be from other SQL Clients you use a different User.

Using squirrel sql with postgresql: backslash syntax error?

I am trying to run basic postgresql commands which start with a backslash within Squirrel SQL sql client. For example, I'd like to be able to type
\dt
to mean "SHOW TABLES" instead of
"SELECT * FROM information_schema.tables WHERE table_schema = 'public';"
This works from the psql command line. However, when I try to run "\dt" within Squirrel I get a syntax error message:
Error: ERROR: syntax error at or near "\"
Position: 1
SQLState: 42601
ErrorCode: 0
I assume there's some kind of SQL syntax checking going on here on the part of Squirrel? Does any one know a way to make PostgreSQL commands which start with a backslash work in Squirrel SQL? I have the Postgres plugin installed...
Thanks,
The backslash commands are part of the psql client, not the PostgreSQL backend server. psql translates them into batches of SQL, which you can see by running psql with the -E flag, and uses the results to produce the displayed output.
This means you can't use these commands from other clients.
Alongside the inability to use pg_dump from within a PostgreSQL protocol session, or get equivalent functionality from the backend server, this is a bit of an FAQ.
At this point the only real option is to use a client that understands the information_schema or PostgreSQL's catalogs (pg_catalog) and can produce the display you want its self. A popular choice is PgAdmin-III, though I stick with psql myself.