From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Bo Lorentsen <bl(at)netgroup(dot)dk> |
Cc: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: Boolean SQL function ? |
Date: | 2001-08-22 14:31:09 |
Message-ID: | 3583.998490669@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Bo Lorentsen <bl(at)netgroup(dot)dk> writes:
> How does one write a SQL FUNCTION that works in a WHERE clause ?
> If fx. I like to make a function called "is_today" that take two dates
> and test if they are within the same day, how can I express this in SQL
> ?
Something like this:
test71=# create function same_day(timestamp, timestamp) returns bool as
test71-# 'select $1::date = $2::date' language 'sql';
CREATE
test71=# select same_day(now(), 'today'::timestamp);
same_day
----------
t
(1 row)
test71=# select same_day(now(), 'yesterday'::timestamp);
same_day
----------
f
(1 row)
test71=#
This particular example doesn't need to use any boolean constants,
but when you do, you can write them like so:
true
false
't'::bool
'f'::bool
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Eisentraut | 2001-08-22 16:09:41 | Re: [SQL] Altering pg_conndefaults |
Previous Message | Bo Lorentsen | 2001-08-22 13:02:45 | Boolean SQL function ? |