Re: Function Problem

From: "Steve Boyle \(Roselink\)" <boylesa(at)roselink(dot)co(dot)uk>
To: "Sharon Cowling" <sharon(dot)cowling(at)sslnz(dot)com>, "Pgsql-Novice \(E-mail\)" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Function Problem
Date: 2002-01-30 22:37:42
Message-ID: 003401c1a9de$baf6b9d0$c55869d5@dualtower
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Sharon,

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

hih
----- Original Message -----
From: "Sharon Cowling" <sharon(dot)cowling(at)sslnz(dot)com>
To: "Pgsql-Novice (E-mail)" <pgsql-novice(at)postgresql(dot)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(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Ewald Geschwinde 2002-01-30 23:05:31 possibly a bug?
Previous Message Torbj=?ISO-8859-1?B?9g==?=rn Andersson 2002-01-30 21:37:24 Re: group by and one column per month?