88 *
99 * Copyright (c) 2000-2008, PostgreSQL Global Development Group
1010 *
11- * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.185 2008/09/23 09:20:38 heikki Exp $
11+ * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.186 2008/11/03 19:08:56 tgl Exp $
1212 */
1313#include "postgres_fe.h"
1414
@@ -826,6 +826,7 @@ describeOneTableDetails(const char *schemaname,
826826PGresult * res = NULL ;
827827printTableOpt myopt = pset .popt .topt ;
828828printTableContent cont ;
829+ bool printTableInitialized = false;
829830int i ;
830831char * view_def = NULL ;
831832char * headers [6 ];
@@ -887,9 +888,10 @@ describeOneTableDetails(const char *schemaname,
887888tableinfo .tablespace = (pset .sversion >=80000 ) ?
888889atooid (PQgetvalue (res ,0 ,6 )) :0 ;
889890PQclear (res );
891+ res = NULL ;
890892
891893/*
892- *This is used to get the valuesof a sequence and storeit in an
894+ *If it's a sequence, fetch its values and storeinto an
893895 * array that will be used later.
894896 */
895897if (tableinfo .relkind == 'S' )
@@ -898,12 +900,14 @@ describeOneTableDetails(const char *schemaname,
898900
899901#define SEQ_NUM_COLS 10
900902printfPQExpBuffer (& buf ,
901- "SELECT sequence_name, last_value, \n"
902- "start_value, increment_by, \n"
903- "max_value, min_value, cache_value, \n"
904- "log_cnt, is_cycled, is_called \n"
905- "FROM \"%s\"" ,
906- relationname );
903+ "SELECT sequence_name, last_value,\n"
904+ " start_value, increment_by,\n"
905+ " max_value, min_value, cache_value,\n"
906+ " log_cnt, is_cycled, is_called\n"
907+ "FROM %s" ,
908+ fmtId (schemaname ));
909+ /* must be separate because fmtId isn't reentrant */
910+ appendPQExpBuffer (& buf ,".%s" ,fmtId (relationname ));
907911
908912result = PSQLexec (buf .data , false);
909913if (!result )
@@ -1000,6 +1004,7 @@ describeOneTableDetails(const char *schemaname,
10001004}
10011005
10021006printTableInit (& cont ,& myopt ,title .data ,cols ,numrows );
1007+ printTableInitialized = true;
10031008
10041009for (i = 0 ;i < cols ;i ++ )
10051010printTableAddHeader (& cont ,headers [i ], true,'l' );
@@ -1030,12 +1035,8 @@ describeOneTableDetails(const char *schemaname,
10301035
10311036/* Type */
10321037printTableAddCell (& cont ,PQgetvalue (res ,i ,1 ), false);
1033-
1034- /* A special 'Value' column for sequences */
1035- if (tableinfo .relkind == 'S' )
1036- printTableAddCell (& cont ,seq_values [i ], false);
1037-
1038- /* Extra: not null and default */
1038+
1039+ /* Modifiers: not null and default */
10391040if (show_modifiers )
10401041{
10411042resetPQExpBuffer (& tmpbuf );
@@ -1057,10 +1058,15 @@ describeOneTableDetails(const char *schemaname,
10571058printTableAddCell (& cont ,modifiers [i ], false);
10581059}
10591060
1061+ /* Value: for sequences only */
1062+ if (tableinfo .relkind == 'S' )
1063+ printTableAddCell (& cont ,seq_values [i ], false);
1064+
10601065/* Storage and Description */
10611066if (verbose )
10621067{
10631068char * storage = PQgetvalue (res ,i ,5 );
1069+
10641070/* these strings are literal in our syntax, so not translated. */
10651071printTableAddCell (& cont , (storage [0 ]== 'p' ?"plain" :
10661072 (storage [0 ]== 'm' ?"main" :
@@ -1593,7 +1599,8 @@ describeOneTableDetails(const char *schemaname,
15931599error_return :
15941600
15951601/* clean up */
1596- printTableCleanup (& cont );
1602+ if (printTableInitialized )
1603+ printTableCleanup (& cont );
15971604termPQExpBuffer (& buf );
15981605termPQExpBuffer (& title );
15991606termPQExpBuffer (& tmpbuf );