Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbf3e675

Browse files
committed
Avoid using a separate query to fetch the default expressions for
columns. Improved version of patch by mallah@trade-india.com.
1 parent0797bb5 commitbf3e675

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

‎src/bin/psql/describe.c

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000-2002 by PostgreSQL Global Development Group
55
*
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 $
77
*/
88
#include"postgres_fe.h"
99
#include"describe.h"
@@ -715,8 +715,10 @@ describeOneTableDetails(const char *schemaname,
715715
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,");
716716
else
717717
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");
720722
if (verbose)
721723
appendPQExpBuffer(&buf,", pg_catalog.col_description(a.attrelid, a.attnum)");
722724
appendPQExpBuffer(&buf,"\nFROM pg_catalog.pg_attribute a");
@@ -762,32 +764,20 @@ describeOneTableDetails(const char *schemaname,
762764
* either */
763765

764766
/* Extra: not null and default */
765-
/* (I'm cutting off the 'default' string at 128) */
766767
if (show_modifiers)
767768
{
768769
resetPQExpBuffer(&tmpbuf);
769-
if (strcmp(PQgetvalue(res,i,2),"t")==0)
770+
if (strcmp(PQgetvalue(res,i,3),"t")==0)
770771
appendPQExpBufferStr(&tmpbuf,"not null");
771772

772773
/* 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)
774776
{
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-
784777
if (tmpbuf.len>0)
785778
appendPQExpBufferStr(&tmpbuf," ");
786-
787779
appendPQExpBuffer(&tmpbuf,"default %s",
788-
result ?PQgetvalue(result,0,0) :"?");
789-
790-
PQclear(result);
780+
PQgetvalue(res,i,2));
791781
}
792782

793783
cells[i*cols+2]=xstrdup(tmpbuf.data);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp