2016-11-16 4 views
0
SELECT  
    to_char(messages. TIME, 'YYYY/MM/DD') AS FullDate, 
    to_char(messages. TIME, 'MM/DD') AS PartialDate, 
      COUNT(CASE WHEN message_definitions.error_category = ? THEN 1 END) AS Errors, 
    error_categories.threshold, 
    COUNT(CASE WHEN messages.message_id = 14 THEN 1 END) AS Picks 
FROM  
    messages LEFT JOIN 
    message_definitions USING (message_id) LEFT JOIN 
    error_categories USING (error_category) 
WHERE 
    (messages. TIME > TIMESTAMP ? - '30 day'::INTERVAL) AND 
    (messages. TIME < TIMESTAMP '2016-08-03' + '1 day'::INTERVAL) AND 
    (messages.system_id = ?) AND 
    (messages.message_id = 14 OR 
    message_definitions.error_category = ?) 
GROUP BY 
    FullDate, PartialDate, error_categories.threshold 
ORDER BY 
    FullDate DESC LIMIT 40 

In der obigen Abfrage, in der where-Klausel (die erste Zeile.? (Nachrichten TIME> TIMESTAMP - '30 Tag ':: INTERVAL) UND ), wenn Parameter typecasted (dh wenn ich legte TIMESTAMP vor?) ich folgende Fehlermeldung

enter image description here

bekommen, die nicht wahr für die Textdaten in der zweiten Zeile ist (Nachrichten. TIME < TIMESTAMP ‚2016.08.03‘ + ' 1 Tag ':: INTERVALL) UND

Wenn ich die Klausel in (Nachrichten ändern. ZEIT>? :: TIMESTAMP - '30 Tag ':: INTERVALL) UND ) (d. H. Ich legte die TIMESTAMP nach?) Kann jemand etwas Licht auf was passiert? Vielen Dank!!

Hinweis: PostGresVersion - 9,6 ODBC-Treiber - 32-Bit-Treiber (unter C:. \ Program Files (x86) \ psqlODBC \ 0905 \ bin \ psqlodbc30a.dll) Gleiche gilt mit Postgres 8.4 als auch.

+0

Wo ist der Code, der Parameter an die obige Abfrage bindet? Versuchen Sie, die obige Abfrage wörtlich auszuführen? –

+0

Ja Derzeit führe ich die Abfrage wörtlich aus. – user6868820

Antwort

0

The documentation sagt:

A constant of an arbitrary type can be entered using any one of the following notations:

type 'string'
'string'::type
CAST ('string' AS type)

The string constant's text is passed to the input conversion routine for the type called type. The result is a constant of the indicated type.

[...]

The :: , CAST() , and function-call syntaxes can also be used to specify run-time type conversions of arbitrary expressions, as discussed in Section 4.2.9. To avoid syntactic ambiguity, the type 'string' syntax can only be used to specify the type of a simple literal constant.

So können Sie diese Syntax verwenden, nur mit einem String-Literal und nicht mit einem Parameter, wie Sie zu tun versuchen.

Verwandte Themen