mercredi 11 mars 2015

syntax error at the end of input (jdbc:postgres)


The below postgresql query works fine if directly run on server. But throws error "Syntax error at the end of input" if run through java program. What is wrong here?


WITH cte AS (

SELECT sum(((plin_sale_priceplin_quantity)-plin_coupon_amt)-(ss_wholesale_costplin_quantity)) AS sum_profit

, sum(plin_sale_price*plin_quantity) AS sum_price

, i_category, i_class

from

mater_purchase2 mp, mater_purchase_lineitem2 mpl

,date_dim d1

,item

,store

where

d1.d_year = 2001

and mp.purc_purchase_id = mpl.plin_purchase_id

and d1.d_date_sk = mp.ss_sold_date_sk

and i_item_sk = mpl.ss_item_sk

and s_store_sk = mp.ss_store_sk

and s_state in ('TN')

GROUP BY i_category, i_class

)

SELECT sum(sum_profit)/sum(sum_price) AS gross_margin

, NULL AS i_category, NULL AS i_class,2 as locheirarchy, 1 AS rank_within_parent

FROM cte


UNION ALL

( SELECT sum(sum_profit)/sum(sum_price) AS gross_margin

, i_category, NULL AS i_class, 1 as locheirarchy

, rank() OVER (ORDER BY sum(sum_profit)/sum(sum_price)) AS rank_within_parent

FROM cte

GROUP BY i_category

)

UNION ALL


(SELECT sum_profit/sum_price AS gross_margin

, i_category, i_class, 0 as locheirarchy

, rank() OVER (PARTITION BY i_category

ORDER BY sum_profit/sum_price) AS rank_within_parent

FROM cte

)

limit 100;





Aucun commentaire:

Enregistrer un commentaire