|
3 | 3 | *
|
4 | 4 | * Copyright 2000-2002 by PostgreSQL Global Development Group
|
5 | 5 | *
|
6 |
| - * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.74 2003/01/07 20:56:06 tgl Exp $ |
| 6 | + * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.75 2003/02/24 03:54:06 tgl Exp $ |
7 | 7 | */
|
8 | 8 | #include"postgres_fe.h"
|
9 | 9 | #include"describe.h"
|
@@ -715,8 +715,10 @@ describeOneTableDetails(const char *schemaname,
|
715 | 715 | printfPQExpBuffer(&buf,"SELECT\n CASE i.indproc WHEN ('-'::pg_catalog.regproc) THEN a.attname\n ELSE SUBSTR(pg_catalog.pg_get_indexdef(attrelid),\n POSITION('(' in pg_catalog.pg_get_indexdef(attrelid)))\n END,");
|
716 | 716 | else
|
717 | 717 | printfPQExpBuffer(&buf,"SELECT a.attname,");
|
718 |
| -appendPQExpBuffer(&buf,"\n pg_catalog.format_type(a.atttypid, a.atttypmod),\n" |
719 |
| -" a.attnotnull, a.atthasdef, a.attnum"); |
| 718 | +appendPQExpBuffer(&buf,"\n pg_catalog.format_type(a.atttypid, a.atttypmod)," |
| 719 | +"\n (SELECT substring(d.adsrc for 128) FROM pg_catalog.pg_attrdef d" |
| 720 | +"\n WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef)," |
| 721 | +"\n a.attnotnull, a.attnum"); |
720 | 722 | if (verbose)
|
721 | 723 | appendPQExpBuffer(&buf,", pg_catalog.col_description(a.attrelid, a.attnum)");
|
722 | 724 | appendPQExpBuffer(&buf,"\nFROM pg_catalog.pg_attribute a");
|
@@ -762,32 +764,20 @@ describeOneTableDetails(const char *schemaname,
|
762 | 764 | * either */
|
763 | 765 |
|
764 | 766 | /* Extra: not null and default */
|
765 |
| -/* (I'm cutting off the 'default' string at 128) */ |
766 | 767 | if (show_modifiers)
|
767 | 768 | {
|
768 | 769 | resetPQExpBuffer(&tmpbuf);
|
769 |
| -if (strcmp(PQgetvalue(res,i,2),"t")==0) |
| 770 | +if (strcmp(PQgetvalue(res,i,3),"t")==0) |
770 | 771 | appendPQExpBufferStr(&tmpbuf,"not null");
|
771 | 772 |
|
772 | 773 | /* handle "default" here */
|
773 |
| -if (strcmp(PQgetvalue(res,i,3),"t")==0) |
| 774 | +/* (note: above we cut off the 'default' string at 128) */ |
| 775 | +if (strlen(PQgetvalue(res,i,2))!=0) |
774 | 776 | {
|
775 |
| -PGresult*result; |
776 |
| - |
777 |
| -printfPQExpBuffer(&buf, |
778 |
| -"SELECT substring(d.adsrc for 128) FROM pg_catalog.pg_attrdef d\n" |
779 |
| -"WHERE d.adrelid = '%s' AND d.adnum = %s", |
780 |
| -oid,PQgetvalue(res,i,4)); |
781 |
| - |
782 |
| -result=PSQLexec(buf.data, false); |
783 |
| - |
784 | 777 | if (tmpbuf.len>0)
|
785 | 778 | appendPQExpBufferStr(&tmpbuf," ");
|
786 |
| - |
787 | 779 | appendPQExpBuffer(&tmpbuf,"default %s",
|
788 |
| -result ?PQgetvalue(result,0,0) :"?"); |
789 |
| - |
790 |
| -PQclear(result); |
| 780 | +PQgetvalue(res,i,2)); |
791 | 781 | }
|
792 | 782 |
|
793 | 783 | cells[i*cols+2]=xstrdup(tmpbuf.data);
|
|