Re: array support patch phase 1 patch - Mailing list pgsql-patches
| From | Joe Conway |
|---|---|
| Subject | Re: array support patch phase 1 patch |
| Date | |
| Msg-id | 3ED94577.5010801@joeconway.com Whole thread Raw |
| In response to | Re: array support patch phase 1 patch (Tom Lane <tgl@sss.pgh.pa.us>) |
| Responses |
Re: array support patch phase 1 patch
Re: array support patch phase 1 patch Re: array support patch phase 1 patch |
| List | pgsql-patches |
Tom Lane wrote:
> Another problem is:
>
> regression=# select distinct array(select * from text_tbl) from foo;
> ERROR: Unable to identify an equality operator for type text[]
>
> This DISTINCT query would fail anyway of course, for lack of a '<'
> operator for arrays, but it seems like we ought to be able to find the
> polymorphic '=' operator.
The attached small patch addresses the above concern (finding
polymorphic "=" operator) by introducing a new function,
IsPolymorphicCoercible().
Now, as predicted, I get:
regression=# select distinct array(select f1 from tse);
ERROR: Unable to identify an ordering operator for type integer[]
Use an explicit ordering operator or modify the query
If there are no objections, please apply.
Next question this begs is, should I work on a '<' operator for arrays?
And if so, how is the behavior defined? Hannu suggested
element-by-element, analogous to character-by-character text string
comparison. Comments?
Thanks,
Joe
Index: src/backend/parser/parse_oper.c
===================================================================
RCS file: /opt/src/cvs/pgsql-server/src/backend/parser/parse_oper.c,v
retrieving revision 1.64
diff -c -r1.64 parse_oper.c
*** src/backend/parser/parse_oper.c 26 May 2003 00:11:27 -0000 1.64
--- src/backend/parser/parse_oper.c 1 Jun 2003 00:01:30 -0000
***************
*** 412,417 ****
--- 412,421 ----
IsBinaryCoercible(arg2, opform->oprright))
return optup;
+ /* last check -- polymorphic types? */
+ if (IsPolymorphicCoercible(arg1 , arg2))
+ return optup;
+
/* nope... */
ReleaseSysCache(optup);
Index: src/backend/parser/parse_coerce.c
===================================================================
RCS file: /opt/src/cvs/pgsql-server/src/backend/parser/parse_coerce.c,v
retrieving revision 2.97
diff -c -r2.97 parse_coerce.c
*** src/backend/parser/parse_coerce.c 26 May 2003 00:11:27 -0000 2.97
--- src/backend/parser/parse_coerce.c 31 May 2003 23:59:07 -0000
***************
*** 1187,1192 ****
--- 1187,1230 ----
return result;
}
+ /* IsPolymorphicCoercible()
+ * Check if srctype and targettype are a polymorphic compatible pair.
+ *
+ * We consider two types polymorphic-coercible if:
+ * 1) both are the same (we should never have been called this way, but what
+ * the heck)
+ * 2) one is ANYARRAY and the other is an array type
+ * 3) one is ANYELEMENT and the other is not an array type
+
+ */
+ bool
+ IsPolymorphicCoercible(Oid srctype, Oid targettype)
+ {
+ /* Case 1: fast path if same type */
+ if (srctype == targettype)
+ return true;
+
+ /* Case 2: check for matching arrays */
+ if (srctype == ANYARRAYOID)
+ if (get_element_type(targettype) != InvalidOid)
+ return true;
+
+ if (targettype == ANYARRAYOID)
+ if (get_element_type(srctype) != InvalidOid)
+ return true;
+
+ /* Case 3: check for matching elements */
+ if (srctype == ANYELEMENTOID)
+ if (get_element_type(targettype) == InvalidOid)
+ return true;
+
+ if (targettype == ANYELEMENTOID)
+ if (get_element_type(srctype) == InvalidOid)
+ return true;
+
+ /* if all else fails... */
+ return false;
+ }
/*
* find_coercion_pathway
Index: src/include/parser/parse_coerce.h
===================================================================
RCS file: /opt/src/cvs/pgsql-server/src/include/parser/parse_coerce.h,v
retrieving revision 1.51
diff -c -r1.51 parse_coerce.h
*** src/include/parser/parse_coerce.h 29 Apr 2003 22:13:11 -0000 1.51
--- src/include/parser/parse_coerce.h 31 May 2003 23:51:19 -0000
***************
*** 36,41 ****
--- 36,42 ----
extern bool IsBinaryCoercible(Oid srctype, Oid targettype);
+ extern bool IsPolymorphicCoercible(Oid srctype, Oid targettype);
extern bool IsPreferredType(CATEGORY category, Oid type);
extern CATEGORY TypeCategory(Oid type);
pgsql-patches by date: