Tom Lane wrote: > Alvaro Herrera <alvhe...@commandprompt.com> writes: > > Note that it introduces a LEFT JOIN on pg_class to itself that's always > > present, even for server versions that do not support reloptions. > > Personally I'd be more worried about the unnest(). Also, please > schema-qualify that function name; you can't assume anything about > the search path here.
This version should fix these issues. I refrained from adding more ? : expressions because it starts getting ugly for my taste.
Index: src/bin/psql/describe.c =================================================================== RCS file: /home/alvherre/cvs/pgsql/src/bin/psql/describe.c,v retrieving revision 1.198 diff -c -p -r1.198 describe.c *** src/bin/psql/describe.c 22 Jan 2009 20:16:08 -0000 1.198 --- src/bin/psql/describe.c 11 Feb 2009 01:19:11 -0000 *************** *** 8,14 **** * * Copyright (c) 2000-2009, PostgreSQL Global Development Group * ! * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.198 2009-01-22 20:16:08 tgl Exp $ */ #include "postgres_fe.h" --- 8,14 ---- * * Copyright (c) 2000-2009, PostgreSQL Global Development Group * ! * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.197 2009/01/20 02:13:42 momjian Exp $ */ #include "postgres_fe.h" *************** describeOneTableDetails(const char *sche *** 871,876 **** --- 871,877 ---- bool verbose) { PQExpBufferData buf; + PQExpBufferData reloptbuf; PGresult *res = NULL; printTableOpt myopt = pset.popt.topt; printTableContent cont; *************** describeOneTableDetails(const char *sche *** 908,923 **** initPQExpBuffer(&title); initPQExpBuffer(&tmpbuf); /* Get general table info */ printfPQExpBuffer(&buf, ! "SELECT relchecks, relkind, relhasindex, relhasrules, %s, " ! "relhasoids" ! "%s%s\n" ! "FROM pg_catalog.pg_class WHERE oid = '%s'", ! (pset.sversion >= 80400 ? "relhastriggers" : "reltriggers <> 0"), ! (pset.sversion >= 80200 && verbose ? ! ", pg_catalog.array_to_string(reloptions, E', ')" : ",''"), ! (pset.sversion >= 80000 ? ", reltablespace" : ""), oid); res = PSQLexec(buf.data, false); if (!res) --- 909,944 ---- initPQExpBuffer(&title); initPQExpBuffer(&tmpbuf); + if (verbose) + { + initPQExpBuffer(&reloptbuf); + if (pset.sversion >= 80400) + { + printfPQExpBuffer(&reloptbuf, + "pg_catalog.array_to_string(c.reloptions || " + "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"); + } + else if (pset.sversion >= 80200) + { + printfPQExpBuffer(&reloptbuf, + "pg_catalog.array_to_string(c.reloptions, ', ')\n"); + } + else + printfPQExpBuffer(&reloptbuf, "''\n"); + } + + /* Get general table info */ printfPQExpBuffer(&buf, ! "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, %s, " ! "c.relhasoids, " ! "%s%s\n" ! "FROM pg_catalog.pg_class c\n " ! "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n" ! "WHERE c.oid = '%s'\n", ! (pset.sversion >= 80400 ? "c.relhastriggers" : "c.reltriggers <> 0"), ! verbose ? reloptbuf.data : "''", ! (pset.sversion >= 80000 ? ", c.reltablespace" : ""), oid); res = PSQLexec(buf.data, false); if (!res) *************** error_return: *** 1672,1677 **** --- 1693,1700 ---- termPQExpBuffer(&buf); termPQExpBuffer(&title); termPQExpBuffer(&tmpbuf); + if (verbose) + termPQExpBuffer(&reloptbuf); if (seq_values) {
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers