Thread: Part 2 of "Intentional, or a bug"....

Part 2 of "Intentional, or a bug"....

From
Kovacs Baldvin
Date:
Hi again.

First of all, tank you for the immediate and precise answers.

My solution to the problem was the following. However, I found
that to be quite slow. I would like to ask if one can suggest me
how to optimize this, because I need this regularly.

CREATE FUNCTION gyegyenlo(text, text) RETURNS boolean AS ' SELECT CASE WHEN $1 is null and $2 is null THEN true
                        ELSE ($1) = ($2)      END;
 
' LANGUAGE 'sql';

CREATE OPERATOR ~= ( leftarg = text, rightarg = text, procedure = gyegyenlo, commutator = ~=
);

After these I use ~= if I need lines with NULLs in both to be selected.

The only problem is that it makes the query very slow. Does anyone
knows how to optimize this?

Thanks,
Baldvin




Re: Part 2 of "Intentional, or a bug"....

From
Tom Lane
Date:
Kovacs Baldvin <kb136@hszk.bme.hu> writes:
> After these I use ~= if I need lines with NULLs in both to be selected.

Perhaps you should reconsider your data model.  You seem to be treating
NULL as if it were a real value, which is something that SQL discourages
rather strongly...
        regards, tom lane


Re: Part 2 of "Intentional, or a bug"....

From
Kovacs Baldvin
Date:
> > After these I use ~= if I need lines with NULLs in both to be selected.
>
> Perhaps you should reconsider your data model.  You seem to be treating

The given column is a date type column, with some records where
"date is not given". This "not given" is represented by NULL.
I saw it more elegant than assigning a date in the very past for
"not given", or using a boolean column called "date given".

After all, I consider using the additional boolean column.

Bye,
Baldvin