Re: pg_query_params() problem with date_trunc() (possibly other functions as well)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: patrick keshishian <pkeshish(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: pg_query_params() problem with date_trunc() (possibly other functions as well)
Date: 2014-05-17 04:42:02
Message-ID: 1558.1400301722@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

patrick keshishian <pkeshish(at)gmail(dot)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)

or if that doesn't work, try this:

... date_trunc('day', now()), date_trunc('day', $1::timestamp)

The syntax TIMESTAMP '...' is only for plain literal constants.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message patrick keshishian 2014-05-17 04:50:02 Re: pg_query_params() problem with date_trunc() (possibly other functions as well)
Previous Message patrick keshishian 2014-05-17 04:37:48 pg_query_params() problem with date_trunc() (possibly other functions as well)