How do I use ROW_NUMBER in DB2 10 on z/OS? - db2

I am running a SQL query and trying to break the results down into chunks.
select task_id, owner_cnum
from (select row_number() over(order by owner_cnum, task_id)
as this_row, wdpt.vtasks.*
from wdpt.vtasks)
where this_row between 1 and 5;
That SQL works with DB2 10.5 on Windows and Linux, but fails on DB2 10.1 on z/OS with the following error messages:
When I run the SQL from IBM DataStudio 4.1.1 running on my Windows machine connected to the database, I am getting:
ILLEGAL SYMBOL "<EMPTY>". SOME SYMBOLS THAT MIGHT BE LEGAL ARE: CORRELATION NAME. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.18.60
When I run my Java program on a zLinux system connecting to the database, I get the following error:
DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=<EMPTY>;CORRELATION NAME, DRIVER=3.65.97
Any ideas what I'm doing wrong?

In some DB2 versions you must use a correlation name for a subselect, as suggested by the error message:
select FOO from (
select FOO from BAR
) as T
Here "T" is the correlation name.

Related

DB2 encrypt field in select statement

So I need to do a select statement, while encrypting a field in SHA2_512. I'm not sure which DB2 version it is, but I tried both queries and neither work.
When trying this query:
SELECT HEX(HASH_SHA256('ABCDEFGHIJKLMNOPQRZTUVWXYZ'))
FROM SYSIBM.SYSDUMMY1;
I get the following error:
Error: DB2 SQL Error: SQLCODE=-440, SQLSTATE=42884,
SQLERRMC=FUNCTION;HASH_SHA256, DRIVER=3.71.22 SQLState: 42884
ErrorCode: -440 Error: DB2 SQL Error: SQLCODE=-514, SQLSTATE=26501,
SQLERRMC=SQL_CURLH200C1, DRIVER=3.71.22 SQLState: 26501 ErrorCode:
-514
While with this query
SELECT hash('Charlie at IBM', 3)
FROM SYSIBM.SYSDUMMYU;
Error: DB2 SQL Error: SQLCODE=-440, SQLSTATE=42884,
SQLERRMC=FUNCTION;HASH, DRIVER=3.71.22 SQLState: 42884 ErrorCode:
-440 Error: DB2 SQL Error: SQLCODE=-514, SQLSTATE=26501, SQLERRMC=SQL_CURLH200C1, DRIVER=3.71.22 SQLState: 26501 ErrorCode:
-514
(while without the hash functions the query runs without any issues). Anyone know how I can fix this issue?
I'm not sure which DB2 version I'm using but by using these queries I get these results:
SELECT GETVARIABLE('SYSIBM.VERSION') FROM SYSIBM.SYSDUMMY1
DSN11015
select GETVARIABLE('SYSIBM.NEWFUN') AS COMPATIBILITY from sysibm.sysdummy1
COMPATIBILITY: V11
https://www.ibm.com/docs/en/db2/11.1?topic=functions-hash
https://www.ibm.com/docs/en/db2-for-zos/12?topic=sf-hash-crc32-hash-md5-hash-sha1-hash-sha256
You appear to be using Db2-v11 for Z/OS "DSN11015" in V11 compatibility mode.
This version lacks the scalar function HASH_SHA256 (and others) which is present in Db2-v12 for z/OS. That is the reason you get sqlcode -440 (no such function HASH...) with your Db2-for-z/os version.
At Version-11 , IBM documents a function ENCRYPT_TDES which may help you.
Background information on using this function.
You can write your own functions if you have the skills.

PSQLEXCEPTION: Unexpected error code "55000" received from data source "FEDSER". Associated text and tokens are "This ResultSet is closed."

I am trying to do the differential data load from db2 to PostgreSQL table through InfoSphere Federation Server.
Followed below steps and got the expeption:
SQL1822N Unexpected error code "55000" received from data source "FEDSER".
Associated text and tokens are "This ResultSet is closed.".
Please find the below steps which I followed:
create wrapper jdbc
DB20000I The SQL command completed successfully.
CREATE SERVER FEDSER TYPE JDBC VERSION '12' WRAPPER JDBC OPTIONS( ADD DRIVER_PACKAGE 'E:\Sandhya\postgresql-8.1-415.jdbc3.jar', URL 'jdbc:postgresql://localhost:5432/SCOPEDB', DRIVER_CLASS 'org.postgresql.Driver', DB2_IUD_ENABLE 'Y', db2_char_blankpadded_comparison 'Y', db2_varchar_blankpadded_comparison 'Y', VARCHAR_NO_TRAILING_BLANKS 'Y', JDBC_LOG 'Y')
DB20000I The SQL command completed successfully.
CREATE USER MAPPING FOR SANAGARW SERVER FEDSER OPTIONS (REMOTE_AUTHID 'postgres',REMOTE_PASSWORD '*****')
DB20000I The SQL command completed successfully
SELECT COUNT(*) FROM "SCOPE".EMPLOYEE
SQL1822N Unexpected error code "55000" received from data source "FEDSER".
Associated text and tokens are "This ResultSet is closed.".
I am using Postgres version 12, Java version "1.8.0_241"
Please help me to resolve this issue. or once connection get created then I can only create the nickname.
Consider using Db2 11.5 instead of InfoSphere Federation Server which went out of support 2017-09-30 https://www.ibm.com/support/lifecycle/#/search?q=InfoSphere%20Federation%20Server
Db2 11.5 includes inbuilt support for PostgreSQL federation in all Db2 editions including Db2 Community Edition
https://www.ibm.com/support/pages/data-source-support-matrix-federation-bundled-db2-luw-v115

Query in RedShift using DBVisualizer fails in a particular instalation

I am running the following query in dBVisualizer
select top 100 * from analytical.dwh_sales where _material = '000032';
And is working propertly
But when the same query is executed in another computer (an export from my dBVisualizer installation to another machine) we are having the following error:
[Code: 500310, SQL State: 42703] [Amazon](500310) Invalid operation: column "loc_XXX " does not exist in dwh_sales;
I dont if you can notice is adding a space to loc_XXX(space) . Not sure if is why is working in a computer and not in another.

Flyway Issue with DB2

I am using flyway for a deployment and the tables built as a result of flyway are all fine.
The issue I have is with the schema_version table. I am unable to query an individual column in the table. I am only able to perform a select *.
The error message I am getting is:
10:35:49 [SELECT - 0 row(s), 0.000 secs] 1) [Error Code: -206, SQL State: 42703] DB2 SQL Error: SQLCODE=-206, SQLSTATE=42703, SQLERRMC=SCRIPT, DRIVER=4.13.127. 2) [Error Code: -727, SQL State: 56098] DB2 SQL Error: SQLCODE=-727, SQLSTATE=56098, SQLERRMC=2;-206;42703;SCRIPT, DRIVER=4.13.127
Try enclosing the column name in double quotes:
select "SCRIPT" from flyway.schema_version
This might help.
Flyway Schema table is designed to be in lower case.
You can change the table name using below config property.
flyway.table=SCHEMA_VERSION
For more details you can check this
https://flywaydb.org/documentation/faq#case-sensitive
Try to make your query like this:
SELECT "version", "installed_on" FROM "schema_version";

displaying db2 error codes in SquirrelSQL

When you run a query in db2 commandline tool you get explanations like:
db2 => select * from sysibm.systables where owner = 'SAM' and type = 'T';
SQL0206N "OWNER" is not valid in the context where it is used.
SQLSTATE=42703
However, when ran in SQL tab in SquirrelSQL you get only:
Error: DB2 SQL Error: SQLCODE=-206, SQLSTATE=42703, SQLERRMC=OWNER, DRIVER=4.13.127
SQLState: 42703
ErrorCode: -206
Does anybody know of a way of making SquirrelSQL display explanation for the error code like db2 cmd line?
OS: Win 7 x64, db2 10.1
There's a bug in DB2 plugin, I have managed to fix it and posted solution at http://sourceforge.net/p/squirrel-sql/bugs/1073/