Re: Problem either with PostgreSQL or with PHP - Mailing list pgsql-general

From tv@fuzzy.cz
Subject Re: Problem either with PostgreSQL or with PHP
Date
Msg-id 22822.62.40.76.70.1270657359.squirrel@sq.gransy.com
Whole thread Raw
In response to Problem either with PostgreSQL or with PHP  (Tuo Pe <tuo_pe@yahoo.com>)
List pgsql-general
> Hi!
>
> I have written this function in PL/pgSQL,
> CREATE OR REPLACE FUNCTION MakeSimpleReservation(integer, integer,
> integer, text, text) RETURNS boolean ...
>
> In my PHP script, I have this code:
>  $start_ts = '2010-04-12 11:00:00';
>  $end_ts   = '2010-04-12 14:00:00';
>
>  $update = pg_query($yhteys, "SELECT MakeSimpleReservation(2, 3, 1,
> '{$start_ts}' , '{$end_ts}');");
>
> On psql, I can run a command such as
>
> select * from MakeSimpleReservation(2, 30, 1, '2010-04-12 11:00:00',
> '2010-04-12 14:00:00');
>
> without any problems, but when I try to run it via PHP, I get this error
> message:
>
> ERROR: function makesimplereservation(integer, integer, integer, unknown,
> unknown) does not exist LINE 1: SELECT MakeSimpleReservation(2, 3, 1,
> '2010-04-12 11:00:00' ... ^ HINT: No function matches the given name and
> argument types. You might need to add explicit type casts.
>
> For some reason, the last two function parameters are not recognized as
> strings. Is this a problem with PHP or with PostgreSQL? Can anyone give me
> advice how to fix this?

(a) Why are you passing timestamps as text? Try to use 'timestamp' instead
of 'text' and then cast the values using ::timestamp (e.g. '2010-04-12
11:00:00'::timestamp).

(b) If you really need to pass the values as text, you can cast using
::text (so '2010-04-12 11:00:00'::text will do the trick).

(c) As the function returns boolean, you should use

    select makesimplereservation(....) AS 'result';

and not 'select * from ...' - this should be used with SRF (set returning
functions) and I'm not sure if it will work with scalar  values.

Tomas


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Problem either with PostgreSQL or with PHP
Next
From: Frank Heikens
Date:
Subject: Re: Problem either with PostgreSQL or with PHP