EnterpriseDB: The Enterprise Postgres Company Postgres Plus Forums: The PostgreSQL Open Source Database from EnterpriseDB
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Members]  Member Listing   [Groups] Back to home page 

Query problem using case with sum from subquery  XML

Forum Index » GridSQL - Developers
Author Message
ranga.gopalan@sorrisotech.com

Member

Joined: 23 Feb 2010 12:55:49
Messages: 19
Offline

Hi,

I am running into a problem with trying to do a CASE statement within a query using summed values from a subquery. Please see SQL example and exception log from server below. (Build is from CVS with debuginfo enabled). Hope you can help.

Thanks,

Ranga




Andrei_M

Senior member

Joined: 19 Dec 2008 01:37:13
Messages: 116
Offline

Hi Ranga,

FYI
We have just fixed the bug and checked in changes to CVS.
Thanks for reporting it.

Andrei

Thanks
Andrei
ranga.gopalan@sorrisotech.com

Member

Joined: 23 Feb 2010 12:55:49
Messages: 19
Offline

Hi Andrei,

I picked up the changes and built and tested again - The original query I posted works. However, I am running into another issue - (which I can work around but I thought I would let you know)



I can work around by avoiding the sub-query (the query itself is generated by a program) - Here is the exception seen in the console log.



Regards,

Ranga

ranga.gopalan@sorrisotech.com

Member

Joined: 23 Feb 2010 12:55:49
Messages: 19
Offline

Hi Andrei,

I grabbed the latest source this morning and tried out with that - I noticed that a related test case fails - The sum/case combination that I described earlier in this message is in some cases being done from a union of two or more tables. In that scenario, I need something like the provided test case below to work - (and it currently doesn't). Please see details below.

Thanks,

Ranga



This fails with the following exception in the log:

Andrei_M

Senior member

Joined: 19 Dec 2008 01:37:13
Messages: 116
Offline

Hi Ranga,

Sorry, last checkin introduced a regression.
Now it is fixed.
Sorry for the inconvenience.

Thanks,
Andrei

Thanks
Andrei
ranga.gopalan@sorrisotech.com

Member

Joined: 23 Feb 2010 12:55:49
Messages: 19
Offline

Hi Andrei,

I tested with the latest and I'm super thrilled that the query in all its complexity works now! - See full example below.



However, I am running into a related parser issue - in this scenario - The query works fine via gs-cmdline.sh - However, fails via JDBC when I specify the value range for AGLIM.f2col using parameters to a prepared statement. I can work around it by hardcoding the values but would prefer to use the PreparedStatement with parameters so that hopefully the repeated parsing of the queries can be avoided.

See code example below:



Output from the program:


Output in console log:
ranga.gopalan@sorrisotech.com

Member

Joined: 23 Feb 2010 12:55:49
Messages: 19
Offline

Hi Andrei,

Other than the JDBC param invocation issue mentioned above, one additional issue remains - the union subquery does not work as described a couple of messages above - I mean a query with a union in the subquery fails as below. - I have attached an exception trace a couple of post above.

Regards,

Ranga

Andrei_M

Senior member

Joined: 19 Dec 2008 01:37:13
Messages: 116
Offline

Hi Ranga,

We have checked in few bug fixes, that should resolve problems you reported here.
Note, for some queries GridSQL can not determine data types of expression, causing query to fail.
The query select bb.f1, sum(bb.f2col) as sumcol from (select f1, f2 as f2col, null as f3col from rol1 union all select f1, null as f2col, f3 as f3col from rol2) bb group by bb.f1; is the case.
To workaround this problem explicit typecast should be used:
select bb.f1, sum(bb.f2col) as sumcol from (select f1, f2 as f2col, null::int as f3col from rol1 union all select f1, null::int as f2col, f3 as f3col from rol2) bb group by bb.f1;

Thanks,
Andrei

Thanks
Andrei
ranga.gopalan@sorrisotech.com

Member

Joined: 23 Feb 2010 12:55:49
Messages: 19
Offline

Hi Andrei,

I updated to the latest from the source and tried - and with your suggestion about the type cast I was able to run the union query successfully. Thanks for that - though I ran into a 10 param limit issue - I posted another message about it.

Regards,

Ranga
 
Forum Index » GridSQL - Developers
Go to:   
Powered by JForum 2.1.8 © JForum Team