*** src/bin/psql/describe.c.orig	Mon Aug 21 11:21:56 2006
--- src/bin/psql/describe.c	Thu Aug 24 17:18:21 2006
***************
*** 14,20 ****
--- 14,22 ----
  #include "settings.h"
  #include "print.h"
  #include "variables.h"
+ #include "libpq-int.h"
  
+ #include <limits.h>
  #include <ctype.h>
  
  #ifdef WIN32
***************
*** 38,43 ****
--- 40,46 ----
  
  static bool add_tablespace_footer(char relkind, Oid tablespace, char **footers,
  					  int *count, PQExpBufferData buf, bool newline);
+ static void AssignSeqValue(PGresult  *resultset);
  
  /*----------------
   * Handlers for various slash commands displaying some sort of list
***************
*** 1499,1504 ****
--- 1502,1508 ----
  	bool		showSeq = strchr(tabtypes, 's') != NULL;
  	bool		showSystem = strchr(tabtypes, 'S') != NULL;
  
+ 	int64 initialSeqValue = LLONG_MAX;
  	PQExpBufferData buf;
  	PGresult   *res;
  	printQueryOpt myopt = pset.popt;
***************
*** 1521,1526 ****
--- 1525,1534 ----
  					  _("table"), _("view"), _("index"), _("sequence"),
  					  _("special"), _("Type"), _("Owner"));
  
+ 	if ((showSeq) && (!showTables))
+ 		appendPQExpBuffer(&buf,  ",\n " INT64_FORMAT "  as \"%s\"", 
+ 						initialSeqValue, _("Seq Value"));
+ 
  	if (showIndexes)
  		appendPQExpBuffer(&buf,
  						  ",\n c2.relname as \"%s\"",
***************
*** 1587,1592 ****
--- 1595,1603 ----
  		myopt.nullPrint = NULL;
  		myopt.title = _("List of relations");
  
+ 		if ((showSeq) && (!showTables))
+ 			AssignSeqValue(res);
+ 
  		printQuery(res, &myopt, pset.queryFout, pset.logfile);
  	}
  
***************
*** 1594,1599 ****
--- 1605,1642 ----
  	return true;
  }
  
+ 
+ /*
+  * \ds
+  *
+  * Assign the respective sequence value.
+  */
+ static void AssignSeqValue(PGresult  *resultset)
+ {
+ 	int i, rows, nfields;
+ 	PQExpBufferData buf;
+ 	PGresult  *seqValue;
+ 
+ 	rows = PQntuples(resultset);
+ 	nfields = PQnfields(resultset);
+ 	
+ 	/* 
+ 	 * Execute the select query to get the sequence value for each sequence separately,
+ 	 * by using the retrieved sequence names from the second field of resultset. 
+ 	 * Re-assign the respective sequence values to the last field of resultset.
+ 	 */
+ 	for(i=0; i<rows; i++)
+ 	{
+ 		initPQExpBuffer(&buf);
+ 		printfPQExpBuffer(&buf, "select last_value from %s", PQgetvalue(resultset, i, 1));
+ 
+ 		seqValue = PSQLexec(buf.data, false);
+ 		termPQExpBuffer(&buf);
+ 		strcpy(resultset->tuples[i][nfields-1].value, seqValue->tuples[0][0].value);
+ 		PQclear(seqValue);
+ 	}
+ }
+ 
  
  /*
   * \dD
