2012-02-09 8 views
12

पर विचार करें इस क्वेरी का है:कॉलम "statement_date" प्रकार की तारीख से है, लेकिन अभिव्यक्ति प्रकार पूर्णांक

INSERT INTO  statement_line_items 
SELECT  count(*)::integer as clicks, sum(amount_cents)::integer as amount_cents, imps.user_id, imps.created_at::date as statement_date 
FROM  impression_events imps 
INNER JOIN transactions t ON t.event_id = imps.id 
    AND  t.event_type = 'ImpressionEvent' 
    AND  amount_cents >= 0 
WHERE  imps.created_at >= (now() - interval '8 days')::date 
    AND  imps.created_at < (now() - interval '7 day')::date 
    AND  imps.clicked = true 
GROUP BY imps.user_id, imps.created_at::date; 

इस लौटा रहा है:

ERROR: column "statement_date" is of type date but expression is of type integer 
LINE 2: ...icks, sum(amount_cents)::integer as amount_cents, imps.user_... 
                  ^
HINT: You will need to rewrite or cast the expression. 

********** Error ********** 

ERROR: column "statement_date" is of type date but expression is of type integer 
SQL state: 42804 
Hint: You will need to rewrite or cast the expression. 
Character: 117 

statement_line_items के लिए मेरे तालिका संरचना है:

"id";    "integer" 
"user_id";   "integer" 
"statement_date"; "date" 
"description";  "character varying(255)" 
"clicks";   "integer" 
"amount_cents"; "integer" 
"created_at";  "timestamp without time zone" 
"updated_at";  "timestamp without time zone" 

उत्तर

13

आप अपने statement_date कॉलम में imps.userid लगा रहे हैं। यह असफल होना है।

count(*)::integer as clicks goes into id 
sum(amount_cents)::integer as amount_cents goes into userid 
imps.user_id goes into statement_date 

आपको आप ऐसा कर सकते डालने कर रहे हैं निर्दिष्ट करने के लिए:

INSERT INTO statement_line_items (col1, col2, ...) 
values (select data_for_col1, data_for_col2, ...) 
+5

आह, मैं धारणा है कि यह एक ही नामित स्तंभ में डाला तहत किया गया। इससे स्पष्ट हुआ। –

+0

मेरे लिए काम करने वाले कथन को सम्मिलित करना था: 'INSERT INTO कथन_लाइन_इटम्स (col1, col2, ...) xyz' से data_for_col1, data_for_col2, ... का चयन करें। मैं अमेज़ॅन रेडशिफ्ट का उपयोग कर रहा हूँ। –

संबंधित मुद्दे