3
3
* back to source text
4
4
*
5
5
* 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 $
7
7
*
8
8
* This software is copyrighted by Jan Wieck - Hamburg.
9
9
*
@@ -136,7 +136,7 @@ static void get_sublink_expr(Node *node, deparse_context *context);
136
136
static void get_from_clause (Query * query , deparse_context * context );
137
137
static void get_from_clause_item (Node * jtnode , Query * query ,
138
138
deparse_context * context );
139
- static void get_opclass_name (Oid opclass , bool only_nondefault ,
139
+ static void get_opclass_name (Oid opclass , Oid actual_datatype ,
140
140
StringInfo buf );
141
141
static bool tleIsArrayAssign (TargetEntry * tle );
142
142
static char * quote_identifier (char * ident );
@@ -408,7 +408,9 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
408
408
sep = "" ;
409
409
for (keyno = 0 ; keyno < INDEX_MAX_KEYS ; keyno ++ )
410
410
{
411
- if (idxrec -> indkey [keyno ] == InvalidAttrNumber )
411
+ AttrNumber attnum = idxrec -> indkey [keyno ];
412
+
413
+ if (attnum == InvalidAttrNumber )
412
414
break ;
413
415
414
416
appendStringInfo (& keybuf , sep );
@@ -419,13 +421,15 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
419
421
*/
420
422
appendStringInfo (& keybuf , "%s" ,
421
423
quote_identifier (get_relid_attribute_name (idxrec -> indrelid ,
422
- idxrec -> indkey [ keyno ] )));
424
+ attnum )));
423
425
424
426
/*
425
427
* If not a functional index, add the operator class name
426
428
*/
427
429
if (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 );
429
433
}
430
434
431
435
if (idxrec -> indproc != InvalidOid )
@@ -446,7 +450,7 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
446
450
appendStringInfo (& buf , "%s(%s)" ,
447
451
quote_identifier (NameStr (procStruct -> proname )),
448
452
keybuf .data );
449
- get_opclass_name (idxrec -> indclass [0 ], true , & buf );
453
+ get_opclass_name (idxrec -> indclass [0 ], procStruct -> prorettype , & buf );
450
454
451
455
ReleaseSysCache (proctup );
452
456
}
@@ -2504,12 +2508,14 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
2504
2508
* get_opclass_name - fetch name of an index operator class
2505
2509
*
2506
2510
* 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.)
2509
2515
* ----------
2510
2516
*/
2511
2517
static void
2512
- get_opclass_name (Oid opclass , bool only_nondefault ,
2518
+ get_opclass_name (Oid opclass , Oid actual_datatype ,
2513
2519
StringInfo buf )
2514
2520
{
2515
2521
HeapTuple ht_opc ;
@@ -2521,7 +2527,7 @@ get_opclass_name(Oid opclass, bool only_nondefault,
2521
2527
if (!HeapTupleIsValid (ht_opc ))
2522
2528
elog (ERROR , "cache lookup failed for opclass %u" , opclass );
2523
2529
opcrec = (Form_pg_opclass ) GETSTRUCT (ht_opc );
2524
- if (! only_nondefault || !opcrec -> opcdefault )
2530
+ if (actual_datatype != opcrec -> opcintype || !opcrec -> opcdefault )
2525
2531
appendStringInfo (buf , " %s" ,
2526
2532
quote_identifier (NameStr (opcrec -> opcname )));
2527
2533
ReleaseSysCache (ht_opc );
0 commit comments