Does Type Have = Operator?

Поиск
Список
Период
Сортировка
От David E. Wheeler
Тема Does Type Have = Operator?
Дата
Msg-id 45164CE9-B56B-4AF9-993A-620CE792D3AC@justatheory.com
обсуждение исходный текст
Ответы Re: Does Type Have = Operator?  (Fabrízio de Royes Mello <fabriziomello@gmail.com>)
Re: Does Type Have = Operator?  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Does Type Have = Operator?  ("David G. Johnston" <david.g.johnston@gmail.com>)
Re: Does Type Have = Operator?  (Euler Taveira <euler@timbira.com.br>)
Список pgsql-hackers
Hackers,

pgTAP has a function that compares two values of a given type, which it uses for comparing column defaults. It looks
likethis: 
   CREATE OR REPLACE FUNCTION _def_is( TEXT, TEXT, anyelement, TEXT )   RETURNS TEXT AS $$   DECLARE       thing text;
BEGIN       IF $1 ~ '^[^'']+[(]' THEN           -- It's a functional default.           RETURN is( $1, $3, $4 );
ENDIF; 
       EXECUTE 'SELECT is('                || COALESCE($1, 'NULL' || '::' || $2) || '::' || $2 || ', '
||COALESCE(quote_literal($3), 'NULL') || '::' || $2 || ', '                || COALESCE(quote_literal($4), 'NULL')
||')' INTO thing;       RETURN thing;   END;   $$ LANGUAGE plpgsql; 

The is() function does an IS DISTINCT FROM to compare the two values passed to it. This has been working pretty well
foryears, but one place it doesn’t work is with JSON values. I get: 
   LINE 1: SELECT NOT $1 IS DISTINCT FROM $2                         ^   HINT:  No operator matches the given name and
argumenttype(s). You might need to add explicit type casts.   QUERY:  SELECT NOT $1 IS DISTINCT FROM $2 

This makes sense, of course, and I could fix it by comparing text values instead of json values when the values are
JSON.But of course the lack of a = operator is not limited to JSON. So I’m wondering if there’s an interface at the SQL
levelto tell me whether a type has an = operator? That way I could always use text values in those situations. 

Thanks,

David



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

Предыдущее
От: Rob Bygrave
Дата:
Сообщение: alter table alter column ... (larger type) ... when there are dependent views
Следующее
От: Ants Aasma
Дата:
Сообщение: Re: asynchronous and vectorized execution