Index: src/backend/commands/sequence.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/backend/commands/sequence.c,v
retrieving revision 1.91
diff -c -r1.91 sequence.c
*** src/backend/commands/sequence.c	2003/02/13 05:25:24	1.91
--- src/backend/commands/sequence.c	2003/02/23 14:49:01
***************
*** 24,42 ****
  #include "utils/acl.h"
  #include "utils/builtins.h"
  
- 
- #ifndef INT64_IS_BUSTED
- #ifdef HAVE_LL_CONSTANTS
- #define SEQ_MAXVALUE	((int64) 0x7FFFFFFFFFFFFFFFLL)
- #else
- #define SEQ_MAXVALUE	((int64) 0x7FFFFFFFFFFFFFFF)
- #endif
- #else							/* INT64_IS_BUSTED */
- #define SEQ_MAXVALUE	((int64) 0x7FFFFFFF)
- #endif   /* INT64_IS_BUSTED */
- 
- #define SEQ_MINVALUE	(-SEQ_MAXVALUE)
- 
  /*
   * We don't want to log each fetching of a value from a sequence,
   * so we pre-log a few fetches in advance. In the event of
--- 24,29 ----
***************
*** 406,412 ****
  				{
  					char		buf[100];
  
! 					snprintf(buf, 100, INT64_FORMAT, maxv);
  					elog(ERROR, "%s.nextval: reached MAXVALUE (%s)",
  						 sequence->relname, buf);
  				}
--- 393,399 ----
  				{
  					char		buf[100];
  
! 					snprintf(buf, sizeof(buf), INT64_FORMAT, maxv);
  					elog(ERROR, "%s.nextval: reached MAXVALUE (%s)",
  						 sequence->relname, buf);
  				}
***************
*** 427,433 ****
  				{
  					char		buf[100];
  
! 					snprintf(buf, 100, INT64_FORMAT, minv);
  					elog(ERROR, "%s.nextval: reached MINVALUE (%s)",
  						 sequence->relname, buf);
  				}
--- 414,420 ----
  				{
  					char		buf[100];
  
! 					snprintf(buf, sizeof(buf), INT64_FORMAT, minv);
  					elog(ERROR, "%s.nextval: reached MINVALUE (%s)",
  						 sequence->relname, buf);
  				}
***************
*** 569,577 ****
  					bufm[100],
  					bufx[100];
  
! 		snprintf(bufv, 100, INT64_FORMAT, next);
! 		snprintf(bufm, 100, INT64_FORMAT, seq->min_value);
! 		snprintf(bufx, 100, INT64_FORMAT, seq->max_value);
  		elog(ERROR, "%s.setval: value %s is out of bounds (%s,%s)",
  			 sequence->relname, bufv, bufm, bufx);
  	}
--- 556,564 ----
  					bufm[100],
  					bufx[100];
  
! 		snprintf(bufv, sizeof(bufv), INT64_FORMAT, next);
! 		snprintf(bufm, sizeof(bufm), INT64_FORMAT, seq->min_value);
! 		snprintf(bufx, sizeof(bufx), INT64_FORMAT, seq->max_value);
  		elog(ERROR, "%s.setval: value %s is out of bounds (%s,%s)",
  			 sequence->relname, bufv, bufm, bufx);
  	}
***************
*** 861,868 ****
  		char		bufm[100],
  					bufx[100];
  
! 		snprintf(bufm, 100, INT64_FORMAT, new->min_value);
! 		snprintf(bufx, 100, INT64_FORMAT, new->max_value);
  		elog(ERROR, "DefineSequence: MINVALUE (%s) must be less than MAXVALUE (%s)",
  			 bufm, bufx);
  	}
--- 848,855 ----
  		char		bufm[100],
  					bufx[100];
  
! 		snprintf(bufm, sizeof(bufm), INT64_FORMAT, new->min_value);
! 		snprintf(bufx, sizeof(bufx), INT64_FORMAT, new->max_value);
  		elog(ERROR, "DefineSequence: MINVALUE (%s) must be less than MAXVALUE (%s)",
  			 bufm, bufx);
  	}
***************
*** 882,889 ****
  		char		bufs[100],
  					bufm[100];
  
! 		snprintf(bufs, 100, INT64_FORMAT, new->last_value);
! 		snprintf(bufm, 100, INT64_FORMAT, new->min_value);
  		elog(ERROR, "DefineSequence: START value (%s) can't be less than MINVALUE (%s)",
  			 bufs, bufm);
  	}
--- 869,876 ----
  		char		bufs[100],
  					bufm[100];
  
! 		snprintf(bufs, sizeof(bufs), INT64_FORMAT, new->last_value);
! 		snprintf(bufm, sizeof(bufm), INT64_FORMAT, new->min_value);
  		elog(ERROR, "DefineSequence: START value (%s) can't be less than MINVALUE (%s)",
  			 bufs, bufm);
  	}
***************
*** 892,899 ****
  		char		bufs[100],
  					bufm[100];
  
! 		snprintf(bufs, 100, INT64_FORMAT, new->last_value);
! 		snprintf(bufm, 100, INT64_FORMAT, new->max_value);
  		elog(ERROR, "DefineSequence: START value (%s) can't be greater than MAXVALUE (%s)",
  			 bufs, bufm);
  	}
--- 879,886 ----
  		char		bufs[100],
  					bufm[100];
  
! 		snprintf(bufs, sizeof(bufs), INT64_FORMAT, new->last_value);
! 		snprintf(bufm, sizeof(bufm), INT64_FORMAT, new->max_value);
  		elog(ERROR, "DefineSequence: START value (%s) can't be greater than MAXVALUE (%s)",
  			 bufs, bufm);
  	}
***************
*** 904,910 ****
  	{
  		char		buf[100];
  
! 		snprintf(buf, 100, INT64_FORMAT, new->cache_value);
  		elog(ERROR, "DefineSequence: CACHE (%s) can't be <= 0",
  			 buf);
  	}
--- 891,897 ----
  	{
  		char		buf[100];
  
! 		snprintf(buf, sizeof(buf), INT64_FORMAT, new->cache_value);
  		elog(ERROR, "DefineSequence: CACHE (%s) can't be <= 0",
  			 buf);
  	}
Index: src/bin/pg_dump/pg_dump.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/bin/pg_dump/pg_dump.c,v
retrieving revision 1.318
diff -c -r1.318 pg_dump.c
*** src/bin/pg_dump/pg_dump.c	2003/02/13 22:56:52	1.318
--- src/bin/pg_dump/pg_dump.c	2003/02/23 14:52:30
***************
*** 52,57 ****
--- 52,59 ----
  #include "catalog/pg_trigger.h"
  #include "catalog/pg_type.h"
  
+ #include "commands/sequence.h"
+ 
  #include "libpq-fe.h"
  #include "libpq/libpq-fs.h"
  
***************
*** 5986,5994 ****
  	PGresult   *res;
  	char	   *last,
  			   *incby,
! 			   *maxv,
! 			   *minv,
  			   *cache;
  	bool		cycled,
  				called;
  	PQExpBuffer query = createPQExpBuffer();
--- 5988,5998 ----
  	PGresult   *res;
  	char	   *last,
  			   *incby,
! 			   *maxv = NULL,
! 			   *minv = NULL,
  			   *cache;
+ 	char		bufm[100],
+ 				bufx[100];
  	bool		cycled,
  				called;
  	PQExpBuffer query = createPQExpBuffer();
***************
*** 5997,6005 ****
  	/* Make sure we are in proper schema */
  	selectSourceSchema(tbinfo->relnamespace->nspname);
  
  	appendPQExpBuffer(query,
! 			"SELECT sequence_name, last_value, increment_by, max_value, "
! 				  "min_value, cache_value, is_cycled, is_called from %s",
  					  fmtId(tbinfo->relname));
  
  	res = PQexec(g_conn, query->data);
--- 6001,6021 ----
  	/* Make sure we are in proper schema */
  	selectSourceSchema(tbinfo->relnamespace->nspname);
  
+ 	snprintf(bufm, sizeof(bufm), INT64_FORMAT, SEQ_MINVALUE);
+ 	snprintf(bufx, sizeof(bufx), INT64_FORMAT, SEQ_MAXVALUE);
+ 
  	appendPQExpBuffer(query,
! 			"SELECT sequence_name, last_value, increment_by, "
! 					"CASE WHEN increment_by > 0 AND max_value = %s THEN NULL "
! 					"     WHEN increment_by < 0 AND max_value = -1 THEN NULL "
! 					"     ELSE max_value "
! 					"END AS max_value, "
! 					"CASE WHEN increment_by > 0 AND min_value = 1 THEN NULL "
! 					"     WHEN increment_by < 0 AND min_value = %s THEN NULL "
! 					"     ELSE min_value "
! 					"END AS min_value, "
! 					"cache_value, is_cycled, is_called from %s",
! 					  bufx, bufm,
  					  fmtId(tbinfo->relname));
  
  	res = PQexec(g_conn, query->data);
***************
*** 6028,6035 ****
  
  	last = PQgetvalue(res, 0, 1);
  	incby = PQgetvalue(res, 0, 2);
! 	maxv = PQgetvalue(res, 0, 3);
! 	minv = PQgetvalue(res, 0, 4);
  	cache = PQgetvalue(res, 0, 5);
  	cycled = (strcmp(PQgetvalue(res, 0, 6), "t") == 0);
  	called = (strcmp(PQgetvalue(res, 0, 7), "t") == 0);
--- 6044,6053 ----
  
  	last = PQgetvalue(res, 0, 1);
  	incby = PQgetvalue(res, 0, 2);
! 	if (!PQgetisnull(res, 0, 3))
! 		maxv = PQgetvalue(res, 0, 3);
! 	if (!PQgetisnull(res, 0, 4))
! 		minv = PQgetvalue(res, 0, 4);
  	cache = PQgetvalue(res, 0, 5);
  	cycled = (strcmp(PQgetvalue(res, 0, 6), "t") == 0);
  	called = (strcmp(PQgetvalue(res, 0, 7), "t") == 0);
***************
*** 6060,6071 ****
  
  		resetPQExpBuffer(query);
  		appendPQExpBuffer(query,
! 				   "CREATE SEQUENCE %s\n    START %s\n    INCREMENT %s\n"
! 				   "    MAXVALUE %s\n    MINVALUE %s\n    CACHE %s%s;\n",
  						  fmtId(tbinfo->relname),
! 						  (called ? minv : last),
! 						  incby, maxv, minv, cache,
! 						  (cycled ? "\n    CYCLE" : ""));
  
  		ArchiveEntry(fout, tbinfo->oid, tbinfo->relname,
  					 tbinfo->relnamespace->nspname, tbinfo->usename,
--- 6078,6100 ----
  
  		resetPQExpBuffer(query);
  		appendPQExpBuffer(query,
! 				   "CREATE SEQUENCE %s\n    START WITH %s\n    INCREMENT BY %s\n",
  						  fmtId(tbinfo->relname),
! 						  (called ? minv : last), incby);
! 
! 		if (maxv)
! 			appendPQExpBuffer(query, "    MAXVALUE %s\n", maxv);
! 		else
! 			appendPQExpBuffer(query, "    NO MAXVALUE\n");
! 
! 		if (minv)
! 			appendPQExpBuffer(query, "    MINVALUE %s\n", minv);
! 		else
! 			appendPQExpBuffer(query, "    NO MINVALUE\n");
! 
! 		appendPQExpBuffer(query,
! 				   "    CACHE %s%s;\n",
! 						  cache, (cycled ? "\n    CYCLE" : ""));
  
  		ArchiveEntry(fout, tbinfo->oid, tbinfo->relname,
  					 tbinfo->relnamespace->nspname, tbinfo->usename,
Index: src/include/commands/sequence.h
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/include/commands/sequence.h,v
retrieving revision 1.21
diff -c -r1.21 sequence.h
*** src/include/commands/sequence.h	2002/06/20 20:29:49	1.21
--- src/include/commands/sequence.h	2003/02/23 14:52:36
***************
*** 89,92 ****
--- 89,105 ----
  extern void seq_undo(XLogRecPtr lsn, XLogRecord *rptr);
  extern void seq_desc(char *buf, uint8 xl_info, char *rec);
  
+ /* Set the upper and lower bounds of a sequence */
+ #ifndef INT64_IS_BUSTED
+ #ifdef HAVE_LL_CONSTANTS
+ #define SEQ_MAXVALUE	((int64) 0x7FFFFFFFFFFFFFFFLL)
+ #else
+ #define SEQ_MAXVALUE	((int64) 0x7FFFFFFFFFFFFFFF)
+ #endif
+ #else							/* INT64_IS_BUSTED */
+ #define SEQ_MAXVALUE	((int64) 0x7FFFFFFF)
+ #endif   /* INT64_IS_BUSTED */
+ 
+ #define SEQ_MINVALUE	(-SEQ_MAXVALUE)
+ 
  #endif   /* SEQUENCE_H */
