Cross join not recognized in HSQL - hsqldb

I am using HSQL ver 1.7. There is a part where I have a HQL like the following
String hql = "from ProductInv prodInv where prodInv.product.id in (:prodList)";
prodList contains list of product ids and the above hql is to get product inventories of the required product ids in prodList.
This hql is translated to a native sql query with "cross join". When this works against my actual db2, it works fine. But my unit tests based on HSQL fails. It says "cross join" is not a recognized keyword.

You need to upgrade to one of the latest versions of HSQLDB (HSQLDB Versions 1.7.x are at least 7 years old).
If your version of Hibernate is 3.6 or later, use the latest HSQLDB (2.2.8 or later). For older versions of Hibernate, use 1.8.1.3.

Related

Oracle 12c documentation for changes / new features to SQL

I just found out that Oracle 12c supports correlating a query several levels deep which is unsupported in 11g and previous versions.
select
*
from
tab1 a
where
not exists
(select
*
from
(select
*
from
tab2 b
where a.X = b.X))
But I could not find this documented in Oracle website. Is there any other such hidden SQL features added to Oracle 12c? Are all such changes to SQL in 12c documented somewhere?
To explain this we need to dive into history a little bit.
Ability to use correlated sub-queries with more than 1 level was also in Oracle 10g R1 and it was properly documented (https://docs.oracle.com/cd/B14117_01/server.101/b10759/queries007.htm) back those days...
Oracle performs a correlated subquery when a nested subquery
references a column from a table referred to a parent statement any
number of levels above the subquery.
... but it was not properly working. :)
So starting with Oracle 10g R2 this functionality was disabled and documentation had changed.
Also (if you have an access) you can see Bug 15990897 : QUERY WITH CORRELATED VARIABLE USED IN 2ND LEVEL SUBQUERY FAILS WITH ORA-904 on Metalink (Fixed in Product Version 12.1.0.1.0). I'm not sure why it's considered as a bug given that it works according to documentation (10g R2, 11g R1, 11g R2) but that is how it is.
So, functionality was disabled after 10.1 and before 12.1 but documentation even for 12.2 (https://docs.oracle.com/en/database/oracle/oracle-database/12.2/sqlrf/Using-Subqueries.html) says
Oracle performs a correlated subquery when a nested subquery
references a column from a table referred to a parent statement one
level above the subquery.
Cut a long story short, this functionality is enabled in 12c R1 and 12c R2 but documentation is not fixed and apparently there is no mentioning about this improvement in New Features guide.
PS. As far as I remember standard SQL 2003 allows correlation only to one level deep - everyone is welcome to check (http://www.wiscorp.com/sql_2003_standard.zip).
But Oracle has a lot of improvements above the standard anyway.

Is there a way to query and find out the version of Vertica installed?

I searched the Vertica documentation for the keywords Version and Version Number.
But I couldn't really get any mention of SQL query to select the version of Vertica installed.
I thought there would be some system table that had some version information but couldn't find any.
Is it not possible to get the version of Vertica installed using an SQL query?
Or is it only possible to access version by logging into the Vertica host and checking some directory?
It can be found here: https://www.vertica.com/docs/latest/HTML/index.htm#Authoring/AdministratorsGuide/Diagnostics/DeterminingYourVersionOfVertica.htm
db=> SELECT VERSION();
VERSION
------------------------------------
Vertica Analytic Database v9.1.0-2
(1 row)
Edit from the comments: hopefully a link to a permanent page, which will not become obsolete when new versions come: https://www.vertica.com/blog/version-vertica-running/
Run below Query:
SELECT VERSION();
Sample Output:
Vertica Analytic Database v9.0.1-9

sql query for header info along with data in columns in informix

I tried many queries like using this
SELECT TABNAME,COLNAME from SYSCAT.COLUMNS where TABNAME='DETAILS'
Also used user_tabs in place of SYSCAT.COLUMNS as well, but it does not work in informix.
Informix does not install the Information Schema tables necessary to support your query; indeed it does not use the schema name ('owner' in Informix parlance) of SYSCAT when it does have (the very old version of) the Information Schema installed.
There's a file $INFORMIXDIR/etc/xpg4_is.sql that you can run for a given database that will install tables informix.TABLES and informix.COLUMNS but not a table user_tabs.

Oracle WITH clause returns no data

I am trying to use a WITH clause in Oracle, but it is not returning any data.
This is the query I am trying to run...
with test as
(select count(*)
from my_table)
select *
from test;
When I run this code, I get back the count of the records in my_table
select count(*)
from my_table
I am on Oracle 10g so the query should work...
select * from v$version;
yields
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for Solaris: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
Could it a permissions issue or something?
*EDIT: *
I believe my question is clear. Using the WITH statement will not return any records for me, even though the "select count(*) from my_table" statement inside the WITH statement works correctly, which would lead me to believe that there is another issue that I am unable to figure out, hence this question :)
EDIT 2
OK, so if I try and execute the query from a linked server from SQL server management studio I get some error information back:
sg 7357, Level 16, State 2, Line 1
Cannot process the object "with test as
(select count(*)
from v$version)
select * from test;". The OLE DB provider "MSDAORA" for linked server "MyServer" indicates that either the object has no columns or the current user does not have permissions on that object.
Maybe the optimizer is materializing the count query (dumb, I agree). It's a shot in the dark but do you have these privileges?
grant query rewrite to youruser;
grant create materialized view to youruser;
Try giving the aggregate an alias name.
with test as
(select count(*) as MyCount
from my_table)
select MyCount
from test;
The following worked just fine for me (10gR2)
SQL> with test as
2 (select count(*)
3 from user_tables)
4 select *
5 from test;
COUNT(*)
----------
593
SQL>
What client are you using?
This question is confusing. Are you saying you are or are not getting back the count from my_table?
You should be getting back the count because that's exactly what you asked for in the with clause.
It's analogous to writing:
select *
from (select count(*) from my_table);
Some people at my company ran into this the other day - we traced it down to the Oracle client version [and thus the OCI.dll] version that was being picked up by PL/SQL developer. Some of our dev PCs had Oracle 8 (!) client installs still knocking around on them as well as more recent versions.
The symptom was that not only were queries written using a WITH clause returning no rows, they were returning no columns either! If you manually set the app to pick up the Oracle 11 oci.dll then it all worked.
I think what is going on is that Oracle 8 predates the WITH clause (introduced in Oracle 9, and enhanced subsequently). Now, mostly you can get different versions of the Oracle client and server to talk to one another. However because the client has a certain amount of 'intelligence', it is supposed to be semi-aware of what sort of operation it is submitting to the database, and so does some form of primitive parse of the SQL. As it doesn't recognize the command as a SELECT, it treats it as some unknown command [e.g. possibly a DDL command] and doesn't recognize it as returning a resultset. If you turn on SQL_TRACE for the session you can see the SQL gets PARSEd and EXECUTEd fine on the server, but that no calls to FETCH are made.
I had a similar thing myself recently when trying to use the new WITH syntax in Oracle 12 that allows an inline function definition. If you try simple examples using an Oracle 11 thick client-based application, such as PL/SQL developer or SQL*Plus, then you get an error. If you use an Oracle 12 client, or a thin-client application that doesn't rely a client-side install, then it works.

Firebird's SQL's Substring function not working

I created a view on a machine using the substring function from Firebird, and it worked. When I copied the database to a different machine, the view was broken. This is the way I used it:
SELECT SUBSTRING(field FROM 5 FOR 15) FROM table;
And this is the output on the machine that does not accept the function:
token unknown: FROM
Both computers have this configuration:
IB Expert version 2.5.0.42 to run the queries and deal with the database.
Firebird version 1.5 as server to database.
BDE Administration version 5.01 installed, with Interbase 4.0 drivers.
Any ideas about why it's behaving differently on these machines?
Make sure Firebird engine is 1.5 and there's no InterBase server running on this same box on the port you expected Firebird 1.5.
Make sure you don't have any UDF called 'substring' registered inside this DB so that Firebird is expecting different parameters.
Different engine versions?
Have you tried naming that expression in the result?
SELECT SUBSTRING(field FROM 5 FOR 15) AS x FROM table;