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 | 3EDA2414.8090707@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
|
List | pgsql-patches |
Tom Lane wrote: > That is surely not what you intended. The test must be whether arg1 and > arg2 are (separately) coercible to the operator's two input types. > Moreover, the test must not be symmetric, any more than > IsBinaryCoercible is. You can coerce int[] to ANYARRAY but not vice > versa. > > A bigger problem is that I doubt this will actually work. Most of the > places that call compatible_oper will then proceed to call the function > from specialized code that does not bother with consing up an expression > tree --- so a polymorphic function is going to fail anyway... > How's this attempt? Couple of issues it raised: 1.) In conjunction with the phase2 patch, which changes array_eq to do an element-by-element equality comparison, I discovered that type "aclitem" has no equality operator, and apparently nothing binary-coercible either. Should I invent "=" for aclitem, or have array_eq fall back to its original byte-by-byte comparison if it doesn't find an equality operator? 2.) I noticed that if I start the postmaster without redirecting to a logfile, I see double error messages in psql. Is this intended? Maybe due to some conf setting? [postgres@dev postgres]$ pg_ctl start LOG: database system was shut down at 2003-06-01 08:58:18 PDT IN: StartupXLOG (xlog.c:2510) LOG: checkpoint record is at 0/5BCDA4 IN: StartupXLOG (xlog.c:2538) LOG: redo record is at 0/5BCDA4; undo record is at 0/0; shutdown TRUE IN: StartupXLOG (xlog.c:2558) LOG: next transaction id: 475; next oid: 17079 IN: StartupXLOG (xlog.c:2562) postmaster successfully started [postgres@dev postgres]$ LOG: database system is ready IN: StartupXLOG (xlog.c:2819) [postgres@dev postgres]$ psql template1 Welcome to psql 7.4devel, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help on internal slash commands \g or terminate with semicolon to execute query \q to quit template1=# 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 IN: ordering_oper (parse_oper.c:202) ERROR: Unable to identify an ordering operator for type integer[] Use an explicit ordering operator or modify the query Joe 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 1 Jun 2003 15:50:25 -0000 *************** *** 1187,1192 **** --- 1195,1222 ---- 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 + * 2) target is ANYARRAY and source is 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 (targettype == ANYARRAYOID) + if (get_element_type(srctype) != InvalidOid) + return true; + + /* if all else fails... */ + return false; + } /* * find_coercion_pathway 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 15:54:41 -0000 *************** *** 412,417 **** --- 412,422 ---- IsBinaryCoercible(arg2, opform->oprright)) return optup; + /* last check -- polymorphic types? */ + if (IsPolymorphicCoercible(arg1 , opform->oprleft) && + IsPolymorphicCoercible(arg2, opform->oprright)) + return optup; + /* nope... */ ReleaseSysCache(optup); 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 1 Jun 2003 15:41:23 -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: