Re: PL/pgSQL & OVERLAPS operator

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: PL/pgSQL & OVERLAPS operator
Date: 2010-03-23 15:33:33
Message-ID: 28749.1269358413@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"A. Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com> writes:
> In response to Tuo Pe :
>> CREATE OR REPLACE FUNCTION TryOverlap(text, text) RETURNS boolean AS $$
>> DECLARE
>> ts_start timestamp with time zone := CAST ($1 AS TIMESTAMP WITH TIME ZONE);
>> ts_end timestamp with time zone := CAST ($2 AS TIMESTAMP WITH TIME ZONE);
>> alku timestamp with time zone;
>> loppu timestamp with time zone;
>> BEGIN
>> SELECT alku,loppu FROM overlaptest WHERE id = 1 INTO alku,loppu;
>> IF ((alku,loppu) OVERLAPS (ts_start,ts_end)) THEN
>> RETURN true;
>> END IF;
>> RETURN false;
>> END;
>> $$ LANGUAGE plpgsql;
>>
>> However, it always seems to return the value false. What's the problem here?
> You have alku and loppu as variable and as table-column, that's a bad
> idea, maybe that's an error, i'm not sure.

Yeah --- that SELECT will result in no change to the variables, ie,
they'll still be NULL. So the OVERLAPS always fails.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2010-03-23 15:49:00 Re: strange
Previous Message Little, Douglas 2010-03-23 14:30:55 Re: string functions and operators