io.crate.shade.org.postgresql.util.PSQLException: ERROR: ArrayIndexOutOfBoundsException: Index 16 out of bounds for length 16 - cratedb

using 4.0.0 version of cratedb
sample sql:
select * from table where col1 = 'exp1' date BETWEEN '2019-01-01' AND '2022-02-14'
right join dim.time where date BETWEEN '2019-01-01' AND '2022-02-14'
in this sql we know first part is empty data, and right join will case this error, but if I narrow down the date to '2020-01-01' AND '2022-02-14' it will work normal, also if I seperate two it works too. and if I delete the col1 filter it work too
error pic
normal pic

This definitely looks like a bug and not a user error.
It might very well be that this is already fixed in a newer version of CrateDB. The current version is 4.7, while 4.0 is more than 2 years old.
Without the table schema (and most likely also dataset) it will not be easy to replicate this. If this can be replicated with a recent version, please report it as bug on Github -> https://github.com/crate/crate/issues

Related

Converting String to Date with SQL in DB2

a similar question has been asked, but the examples use different formats so I haven't been able to solve my problem. For some reason, the database my company uses stores dates as the following:
1131112
1130919
The first is November 12, 2013; the second is September 19, 2013. Not sure why there is a 1 at the beginning. I am trying to convert it to mm/dd/yy so I can use VBA to just grab invoices that are within a user specified date.
The code I am using is the following which results in a database error '1004':
SELECT date(translate('xyymmdd',INDATE,'mmddyy')) FROM INVOICED WHERE (INMFGR || INCOLO || INPATT = 'MMMTEST')
Depending on your DB2 version and platform (which you strangely did not indicate), you might be able to do something like
select to_date(substr(INDATE,2),'yymmdd') from INVOICED
PS. Your use of translate() seems wrong. You can look up its proper usage in the manual for the appropriate DB2 version.

Oracle 9i index error

I have the following query:
select *
from gps_servicio ser
where ser.id in (select idserv from gps_agentes where idagen = 8073061);
This query works perfectly until I make an index in the table gps_agentes, on the field idserv (asc one). If I do that, the query brokes and I get no results from it. Is this a bug?
Both gps_servicio.id and gps_agentes.idserv are number(10,0) fields, and I have a FK on gps_agentes.idserv that points to gps_servicio.id.
Thx for your time!
If the results of a query change when you create an index, that indicates a bug, yes. If you are encountering a bug, you would need to report that to Oracle Support to determine whether the bug you are encountering is already fixed by an existing patch or whether it is a new bug that no one has encountered before.
However, given that you say that you are using 9i, a version of the database that is at least 5 major releases old and has been out of primary support for many years, my wager is that you are running without a support contract and without access to Oracle Support. Are you at least running the latest patchset of whatever version of Oracle you are using ("9i" covers two major releases, 9.0.1 and 9.2)?

IBM Informix SQL Syntax assistance

Wondering if anyone may be able to help me with some SQL here. I'm tasked with retrieving some data from a legacy DB system - It's an IBM Informix DB running v7.23C1. It may well be that what I'm trying to do here is pretty simple, but for the life of me I can't figure it out.
I'm used to MS SQL Server, rather than any other DB system and this one seems quite old: http://publib.boulder.ibm.com/epubs/pdf/3731.pdf (?)
Basically, I just want to run a query that includes nesting, but I can't seem to figure out how to do this. So for example, I have a query that looks like this:
SELECT cmprod.cmp_product,
(stock.stk_stkqty - stock.stk_allstk) stk_bal,
stock.stk_ospurch,
stock.stk_backord,
'Current Sales Period',
'Current Period -1',
'Current Period -2',
cmprod.cmp_curcost,
stock.stk_credate,
stock.stk_lastpurch,
stock.stk_binref
FROM informix.stock stock,
informix.cmprod cmprod
WHERE stock.stk_product = cmprod.cmp_product
AND (cmp_category = 'VOLV'
OR cmp_category = 'VOLD'
OR cmp_category = 'VOLA')
AND stk_loc = 'ENG';
Now, basically where I have values like 'Current Period -1' I want to include a nested field which will run a query to get the sales within a given date range. I'm sure I can put those together separately, but can't seem to get the compiler to be happy with my code when executed altogether.
Probably something like (NB, this specific query is for another column, but you get the idea):
SELECT s.stmov_product, s.stmov_trandate, s.stmov_qty
FROM informix.stmove s
WHERE s.stmov_product = '1066823'
AND s.stmov_qty > 0
AND s.stmov_trandate IN (
SELECT MAX(r.stmov_trandate)
FROM informix.stmove r
WHERE r.stmov_product = '1066823'
AND r.stmov_qty > 0)
What makes things a little worse is I don't have access to the server that this DB is running on. At the moment I have a custom C# app that connects via an ODBC driver and executes the raw SQL, parsing the results back into a .CSV.
Any and all help appreciated!
Under all circumstances, Informix 7.23 is so geriatric that it is unkind to be still running it. It is not clear whether this is an OnLine (Informix Dynamic Server, IDS) or SE (Standard Engine) database. However, 7.23 was the version prior to the Y2K-certified 7.24 releases, so it is 15 years old or thereabouts, maybe a little older.
The syntaxes supported by Informix servers back in the days of 7.23 were less comprehensive than they are in current versions. Consequently, you'll need to be careful. You should have the manuals for the server — someone, somewhere in your company should. If not, you'll need to try finding it in the graveyard manuals section of the IBM Informix web pages (start at http://www.informix.com/ for simplicity of URL; however, archaic manuals take some finding, but you should be able to get there from http://pic.dhe.ibm.com/infocenter/ifxhelp/v0/index.jsp choosing 'Servers' in the LHS).
If you are trying to write:
SELECT ...
(SELECT ... ) AS 'Current - 1',
(SELECT ... ) AS 'Current - 2',
...
FROM ...
then you need to study the server SQL Syntax for 7.23 to know whether it is allowed. AFAICR, OnLine (Informix Dynamic Server) would allow it and SE probably would not, but that is far from definitive. I simply don't remember what the limitations were in that ancient a version.
Judging from the 7.2 Informix Guide to SQL: Syntax manual (dated April 1996 — 17 years old), you cannot put a (SELECT ...) in the select-list in this version of Informix.
You may have to create a temporary table holding the results you want (along with appropriate key information), and then select from the temporary table in the main query.
This sort of thing is one of the problems with not updating your server for so long.
Sorry to be blunt, but can you at least have mercy on us by shortening the syntax?.. table.columns can be presented AS aliases. Meanwhile, if you cant upgrade to a newer version of Informix, you will have to rely on one or more SELECT INTO temp table queries in order to achieve your objective, which BTW, would make your coding more portable across different versions. You also have to evaluate whether using TEMP tables implies unacceptable processing times.

Shorter Date Interval results in longer execution time

I have this query:
SELECT
COUNT(*) AS 'RedactedCount'
,s.Redacted1
,s.[Redacted2]
,s.[Redacted3] AS 'Redacted3'
FROM RedactedTable1 s
LEFT OUTER JOIN RedactedTable2 g ON s.Redacted5= g.Redacted5
WHERE g.Redacted6= 31013 AND s.DateTime >= '2013-03-02 00:00:00'
GROUP BY s.Redacted1,s.Redacted2, s.Redacted3
Which have a very odd behavior. This query takes a whole 1min30secs to complete. Should I change de date to 2013-04-02 00:00:00 (today as I'm writing this post), it is near instant, which is the expected behavior.
But if I change the date to 2013-02-02 (a 2 months time span instead of 1), the query takes only 20 secs.
Does Anyone has encountered this problem ? I am completely stunned on the result. It will also be an important SQL request of a web application that I am working on.
Microsoft SQL Server Management Studio 11.0.3128.0
Microsoft Data Access Components (MDAC) 6.1.7601.17514
Microsoft MSXML 3.0 6.0
Microsoft Internet Explorer 9.0.8112.16421
Microsoft .NET Framework 4.0.30319.296
Système d'exploitation 6.1.7601
Note: The database is poorly designed, and contains absolutely no indexes. Yes, this is bad. Unfortunately, this is a commercial software and I have no rights to make changes on the database model. However, I do not think that the problem I have is caused by this.
P.S.: Sorry if my query is heavily redacted as I am on a strict NDA. I tried to made it as readable as possible.
Thanks !
First of all, it is pointless to put a predicate condition on a table on the outer side of an outer join. As soon as you do this, all rows in the final result set that do not have a match in that table are eliminated, effectively making the overall query behave as though it was an inner join.
The condition on RedactedTable2.Redacted6 should be part of the join conditions if you want the join to include rows where there is no matching row in table RedactedTable2.
SELECT COUNT(*) AS 'RedactedCount',
s.Redacted1, s.[Redacted2],
s.[Redacted3] AS 'Redacted3'
FROM RedactedTable1 s
LEFT JOIN RedactedTable2 g
ON g.Redacted5= s.Redacted5
And g.Redacted6= 31013
WHERE s.DateTime >= '2013-03-02 00:00:00'
GROUP BY s.Redacted1,s.Redacted2, s.Redacted3
As to why the difference in performance, my suspicion is that your issue is caused by something in the data in the tables that is causing the query processor to use a different execution plan in one case than it was in the other. This can easily happen. If the optimizer "guesses" that it would need to examine more than a certain percentage of data rows using one query execution plan, based on database statistics about the distribution of data values in the tables), then it will switch to a different plan.
Run both queries with the ShowPlan option turned on, and look and see what the differences are.
In addition to what Charles suggested you might ask the database administrator (assuming you have one) to run UPDATE STATISTICS on at least RedactedTable1 and RedactedTable2. UPDATE STATISTICS requires you to have ALTER permissions on the table/view so I doubt you have permissions to run it. But you can probably ask for it to be done. Problems like what you are describing are frequently caused by out of date statistics.
Aaron Bertrand got the answer in a comment.
This problem was caused by parameter sniffing done by MSSQL.
Declaring and using dummy variables prevents MSSQL to falsely optimize the query using past optimizations.
The following link helped me learn about parameter sniffing http://blogs.technet.com/b/mdegre/archive/2012/03/19/what-is-parameter-sniffing.aspx

MySQL Date Query issue

I have questions regarding MySQL date and querying with it.
First:
SELECT * FROM post WHERE DATE(Post_Date)="2009-03-25"
returns 0 results
SELECT * FROM post WHERE Post_Date="2009-03-25"
returns 71 results
SELECT * FROM post WHERE Post_Date>="2009-03-25"
returns 379 results
I understand that the second query returning 71 results match only posts with 2009-03-25 00:00:00 as the Post_Date and the third query shows everything. BUT why does the first query SHOW 0 RESULTS?? Please help! I checked the MySQL cnf and the date_format is set to %Y-%m-%d
Second:
SELECT * FROM post WHERE DATE(Post_Date)="2009-03-25"
RETURNS results on WINDOWS!
SELECT * FROM post WHERE DATE(Post_Date)="2009-03-25"
NO RESULTS in Linux!
Any pointers will be helpful!
Is there a configuration file that I need to change to make this work in Linux?
Diagnostic step: run the query SELECT DATE('2009-03-25 08:30:00') on each system. The result will probably tell you what's going on. (Likely a version issue.)
Not sure what to day about your first part, but as for the second: Have you check to make sure that both your servers on windows and Linux have the same data in their respective databases? If you are sure that they are, you may want to check if the Linux database give any results for that year or year-month rather than only the specific year-month-date.