*** ./src/bin/psql/describe.c.orig Wed Mar 21 23:00:19 2001 --- ./src/bin/psql/describe.c Fri Oct 12 22:27:25 2001 *************** *** 748,754 **** /* count indices */ if (!error && tableinfo.hasindex) { ! sprintf(buf, "SELECT c2.relname\n" "FROM pg_class c, pg_class c2, pg_index i\n" "WHERE c.relname = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n" "ORDER BY c2.relname", --- 748,754 ---- /* count indices */ if (!error && tableinfo.hasindex) { ! sprintf(buf, "SELECT c2.relname, i.indkey, i.indisprimary, i.indisunique\n" "FROM pg_class c, pg_class c2, pg_index i\n" "WHERE c.relname = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n" "ORDER BY c2.relname", *************** *** 810,826 **** /* print indices */ for (i = 0; i < index_count; i++) { ! sprintf(buf, "%s %s", ! index_count == 1 ? "Index:" : (i == 0 ? "Indices:" : " "), ! PQgetvalue(result1, i, 0) ); ! if (i < index_count - 1) ! strcat(buf, ","); ! footers[count_footers++] = xstrdup(buf); } ! ! /* print contraints */ for (i = 0; i < constr_count; i++) { sprintf(buf, "%s %s", --- 810,847 ---- /* print indices */ for (i = 0; i < index_count; i++) { ! char *indexname, *indexlist; ! indexname = PQgetvalue(result1, i, 0); ! sprintf(buf, "%s %s%s%s", ! index_count == 1 ? "*Index: " : (i == 0 ? "*Indices:" : " "), ! indexname, ! strcmp(PQgetvalue(result1, i, 2), "t") == 0 ? " [PRIMARY KEY]" : "", ! strcmp(PQgetvalue(result1, i, 3), "t") == 0 ? " [UNIQUE]" : "" ); ! ! /* strtokx is overkill here */ ! char indexchar[5]; /* Should be plenty */ ! int indexnumber=0; ! indexlist = PQgetvalue(result1, i, 1); ! int j,found; ! for (j=0,found=0;j<=strlen(indexlist); j++) { ! if (indexlist[j] == 0 || indexlist[j] == 32) { ! indexnumber = atoi(indexchar); ! if (indexnumber>0) /* pg_class has a -2! */ ! { ! strcat(cells[(indexnumber-1) * cols + 2], cells[(indexnumber-1) * cols +2][0] ? " *" : "*"); ! strcat(buf, ++found==1 ? " (" : ", "); ! strcat(buf, cells[(indexnumber-1) * cols]); ! } ! indexchar[0] = '\0'; ! } ! else { strcat(indexchar,&indexlist[j]); } ! } ! strcat(buf, ")"); footers[count_footers++] = xstrdup(buf); } ! ! /* print contraints */ for (i = 0; i < constr_count; i++) { sprintf(buf, "%s %s",