2016-03-30 14 views
0

Ich habe einen Syntaxfehler, die ich jetzt nicht mehr für eine Stunde lösen:Syntaxfehler in Amazon Redshift

ERROR: 42601: syntax error at or near ")"

with all_comp_prices as 
(
    SELECT distinct 
     m2198.to_product_id AS competitor_product_id, 
     h_comp.when_seen, 
     h_comp.when_seen/86400 AS day, 
     h_comp.price 
    FROM 
     tbl_productmatch_2198 as m2198 
     JOIN 
     (
     select * from tbl_producthistory_2414 
     union select * from tbl_producthistory_2415 
     -- insert union more competitors here 
     ) 
     as h_comp 

     ON h_comp.product_id = m2198.to_product_id 
    WHERE 
     h_comp.when_seen >= extract(epoch from (getdate() - INTERVAL '7 DAYS')) 
) 
select 2198 as customer_site, 
TIMESTAMP 'epoch' + lt.day*86400 * INTERVAL '1 second' as date, 
sum(if(ap.price is null,1,0)) as no_price_competitors_products_count, 
sum(if(ap.price is null,1,0))/1 as ratio_to_total_competitors_products 
from 
(
    select acp.competitor_product, max(acp.when_seen) latest_time, acp.day from 
    all_comp_prices as acp 
    group by acp.competitor_product, acp.day 
) as lt -- latest times for each product per day 
join 
(
    all_comp_prices as ap -- all prices for all times 
) 
on lt.latest_time=ap.when_seen and lt.competitor_product=ap.competitor_product 
group by lt.day 
; 

Ich habe versucht, die Select-Anweisung innerhalb der Schließung laufen und es läuft wie erwartet . Ich nehme an, der Fehler ist irgendwo unter select 2198 as customer_site, ...

Ich gehe mit MySql Logik (mit Ausnahme der WITH Schließung), so vielleicht mein Fehler stammt daraus. Jeder?

+1

Warum bei Epoche zu arbeiten, wenn Sie ein ISO-Datum oder Zeitstempel verwenden könnten? Es erleichtert das Codieren und Debuggen erheblich. Das Lesen des Handbuchs hilft auch ... –

Antwort

0

I umgewandelt, um die IF-CASE und die Fehler kamen nie zurück:

with all_comp_prices as 
(
    SELECT distinct 
     m2198.to_product_id AS competitor_product_id, 
     h_comp.when_seen, 
     h_comp.when_seen/86400 AS day, 
     h_comp.price 
    FROM 
     tbl_productmatch_2198 as m2198 
     JOIN 
     (
     select * from tbl_producthistory_2414 
     union select * from tbl_producthistory_2415 
     -- insert union more competitors here 
     ) 
     as h_comp 

     ON h_comp.product_id = m2198.to_product_id 
    WHERE 
     h_comp.when_seen >= extract(epoch from (getdate() - INTERVAL '7 DAYS')) 
) 
select 2198 as customer_site, 
TIMESTAMP 'epoch' + lt.day*86400 * INTERVAL '1 second' as date, 
sum(CASE WHEN ap.price is null THEN 1 else 0 END) as no_price_competitors_products_count, 
from 
(
select acp.competitor_product_id, max(acp.when_seen) latest_time, acp.day from 
    all_comp_prices as acp 
    group by acp.competitor_product_id, acp.day 
) as lt -- latest times for each products per day 
join 
all_comp_prices as ap -- all prices for all times 
on lt.latest_time=ap.when_seen and lt.competitor_product_id=ap.competitor_product_id 
group by date 
+0

Ich arbeite mit Amazon Redshift und hier ist die Dokumentation dafür: http://docs.aws.amazon.com/redshift/latest/dg/r_GETDATE.html –

+0

Nun behaupteten Sie, Sie arbeiten mit PostgreSQL –

+0

Meine Schuld habe ich nicht erwähnt (bearbeitet die Frage). Dachte, die Syntax ist völlig die gleiche, da Redshift auf Postgresql basiert. –

Verwandte Themen