Re: Function Problem - Mailing list pgsql-novice

From Steve Boyle \(Roselink\)
Subject Re: Function Problem
Date
Msg-id 003401c1a9de$baf6b9d0$c55869d5@dualtower
Whole thread Raw
In response to Function Problem  (Sharon Cowling <sharon.cowling@sslnz.com>)
List pgsql-novice
Sharon,

try it with WHERE date_key_due > current_date instead of your sub-select.

hih
----- Original Message -----
From: "Sharon Cowling" <sharon.cowling@sslnz.com>
To: "Pgsql-Novice (E-mail)" <pgsql-novice@postgresql.org>
Sent: Wednesday, January 30, 2002 1:47 AM
Subject: [NOVICE] Function Problem


> I have a problem with a function I am creating:
>
> CREATE FUNCTION overdue_key() returns int as '
> BEGIN
> UPDATE faps_key SET
> status = ''Overdue''
> WHERE (select key_code from faps_key
> where date_key_due > current_date);
> RETURN 1;
> END;'
> LANGUAGE 'plpgsql';
>
> user=> select overdue_key();
> ERROR:  WHERE clause must return type bool, not type varchar
>
> I understand the error message, but I am unsure as to how to go about
achieving my desired results.
> I know how to do this using cursors inside a stored procedure in Oracle,
but I understand that I cannot use cursors inside a function in Postgres in
the version I am using: 7.1.3
>
> If a key is overdue - (the date_key_due > current_date) then I want to
update the status of each over due key to 'Overdue'
>
> Example of faps_table:
>
> user=> select key_code, permit_id, date_key_issued, date_key_due, status
from faps_key;
>  key_code | permit_id | date_key_issued | date_key_due |  status
> ----------+-----------+-----------------+--------------+-----------
>  B4       |           |                 |              | Available
>  A13      |           |                 |              | Available
>  B1       |           |                 |              | Available
>  A11      |      1141 | 29/01/2002      | 02/02/2002   | Issued
>  A14      |      1145 | 29/01/2002      | 12/02/2002   | Issued
>  A12      |      1146 | 29/01/2002      | 02/02/2002   | Issued
>  B2       |      1147 | 29/01/2002      | 03/02/2002   | Issued
>  B3       |           |                 |              | Available
>  B5       |      1148 | 29/01/2002      | 01/02/2002   | Issued
>  A15      |      1149 | 29/01/2002      | 30/01/2002   | Issued
>
> List of current overdue keys, they have a status of issued, when function
is run I want to update the status to 'Overdue'
>
> user=> select key_code, permit_id, status from faps_key where date_key_due
> current_date;
>  key_code | permit_id | status
> ----------+-----------+--------
>  A11      |      1141 | Issued
>  A14      |      1145 | Issued
>  A12      |      1146 | Issued
>  B2       |      1147 | Issued
>  B5       |      1148 | Issued
> (5 rows)
>
> Any ideas, pointers, documentation?!
>
> Regards,
>
> Sharon Cowling
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>


pgsql-novice by date:

Previous
From: Torbjörn Andersson
Date:
Subject: Re: group by and one column per month?
Next
From: Ewald Geschwinde
Date:
Subject: possibly a bug?