33 *back to source text
44 *
55 * IDENTIFICATION
6- * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.83 2001/10/01 20:15:26 tgl Exp $
6+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.84 2001/10/04 22:00:10 tgl Exp $
77 *
88 * This software is copyrighted by Jan Wieck - Hamburg.
99 *
@@ -136,7 +136,7 @@ static void get_sublink_expr(Node *node, deparse_context *context);
136136static void get_from_clause (Query * query ,deparse_context * context );
137137static void get_from_clause_item (Node * jtnode ,Query * query ,
138138deparse_context * context );
139- static void get_opclass_name (Oid opclass ,bool only_nondefault ,
139+ static void get_opclass_name (Oid opclass ,Oid actual_datatype ,
140140StringInfo buf );
141141static bool tleIsArrayAssign (TargetEntry * tle );
142142static char * quote_identifier (char * ident );
@@ -408,7 +408,9 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
408408sep = "" ;
409409for (keyno = 0 ;keyno < INDEX_MAX_KEYS ;keyno ++ )
410410{
411- if (idxrec -> indkey [keyno ]== InvalidAttrNumber )
411+ AttrNumber attnum = idxrec -> indkey [keyno ];
412+
413+ if (attnum == InvalidAttrNumber )
412414break ;
413415
414416appendStringInfo (& keybuf ,sep );
@@ -419,13 +421,15 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
419421 */
420422appendStringInfo (& keybuf ,"%s" ,
421423quote_identifier (get_relid_attribute_name (idxrec -> indrelid ,
422- idxrec -> indkey [ keyno ] )));
424+ attnum )));
423425
424426/*
425427 * If not a functional index, add the operator class name
426428 */
427429if (idxrec -> indproc == InvalidOid )
428- get_opclass_name (idxrec -> indclass [keyno ], true,& keybuf );
430+ get_opclass_name (idxrec -> indclass [keyno ],
431+ get_atttype (idxrec -> indrelid ,attnum ),
432+ & keybuf );
429433}
430434
431435if (idxrec -> indproc != InvalidOid )
@@ -446,7 +450,7 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
446450appendStringInfo (& buf ,"%s(%s)" ,
447451quote_identifier (NameStr (procStruct -> proname )),
448452keybuf .data );
449- get_opclass_name (idxrec -> indclass [0 ],true ,& buf );
453+ get_opclass_name (idxrec -> indclass [0 ],procStruct -> prorettype ,& buf );
450454
451455ReleaseSysCache (proctup );
452456}
@@ -2504,12 +2508,14 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
25042508 * get_opclass_name- fetch name of an index operator class
25052509 *
25062510 * The opclass name is appended (after a space) to buf.
2507- * If "only_nondefault" is true, the opclass name is appended only if
2508- * it isn't the default for its datatype.
2511+ *
2512+ * Output is suppressed if the opclass is the default for the given
2513+ * actual_datatype. (If you don't want this behavior, just pass
2514+ * InvalidOid for actual_datatype.)
25092515 * ----------
25102516 */
25112517static void
2512- get_opclass_name (Oid opclass ,bool only_nondefault ,
2518+ get_opclass_name (Oid opclass ,Oid actual_datatype ,
25132519StringInfo buf )
25142520{
25152521HeapTuple ht_opc ;
@@ -2521,7 +2527,7 @@ get_opclass_name(Oid opclass, bool only_nondefault,
25212527if (!HeapTupleIsValid (ht_opc ))
25222528elog (ERROR ,"cache lookup failed for opclass %u" ,opclass );
25232529opcrec = (Form_pg_opclass )GETSTRUCT (ht_opc );
2524- if (! only_nondefault || !opcrec -> opcdefault )
2530+ if (actual_datatype != opcrec -> opcintype || !opcrec -> opcdefault )
25252531appendStringInfo (buf ," %s" ,
25262532quote_identifier (NameStr (opcrec -> opcname )));
25272533ReleaseSysCache (ht_opc );