Re: pg_query_params() problem with date_trunc() (possibly other functions as well) - Mailing list pgsql-general

From patrick keshishian
Subject Re: pg_query_params() problem with date_trunc() (possibly other functions as well)
Date
Msg-id CAN0yQBpF79g5xQsJgTGrRaNjhD4=v8m9ODFggS5Mv2OU3LVSYw@mail.gmail.com
Whole thread Raw
In response to Re: pg_query_params() problem with date_trunc() (possibly other functions as well)  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
On 5/16/14, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> patrick keshishian <pkeshish@gmail.com> writes:
>> I started to look into using pg_query_params() with some
>> php scripts, but ran into this issue where I get:
>
>> PHP message: PHP Warning: pg_query_params(): Query failed: ERROR:
>> invalid input syntax for type timestamp: "$1"
>> LINE 1: ... date_trunc('day', now()), date_trunc('day', TIMESTAMP '$1')
>
> You probably want just this:
>
> ... date_trunc('day', now()), date_trunc('day', $1::timestamp)

This worked.

Thank you for your quick response!
--patrick

>
> The syntax TIMESTAMP '...' is only for plain literal constants.
>
>             regards, tom lane
>


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: pg_query_params() problem with date_trunc() (possibly other functions as well)
Next
From: Joe Van Dyk
Date:
Subject: Adding a not null constraint faster