Re: Boolean SQL function ?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Boolean SQL function ?
Дата
Msg-id 3583.998490669@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Boolean SQL function ?  (Bo Lorentsen <bl@netgroup.dk>)
Список pgsql-novice
Bo Lorentsen <bl@netgroup.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

В списке pgsql-novice по дате отправления:

Предыдущее
От: Bo Lorentsen
Дата:
Сообщение: Boolean SQL function ?
Следующее
От: Hanbiao Wang
Дата:
Сообщение: installation problem