mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-10-03 02:26:52 +02:00
> > - Move SEQ_MAXVALUE, SEQ_MINVALUE definitions to sequence.h
> > > > - Add check in pg_dump to see if the value returned is the max /min > > values and replace with NO MAXVALUE, NO MINVALUE. > > > > - Change START and INCREMENT to use START WITH and INCREMENT BY syntax. > > This makes it a touch easier to port to other databases with sequences > > (Oracle). PostgreSQL supports both syntaxes already. > > + char bufm[100], > + bufx[100]; > > This seems to be an arbitary size. Why not set it to the actual maximum > length? > > Also: > > + snprintf(bufm, 100, INT64_FORMAT, SEQ_MINVALUE); > + snprintf(bufx, 100, INT64_FORMAT, SEQ_MAXVALUE); > > sizeof(bufm), sizeof(bufx) is probably the more > maintenance-friendly/standard way to do it. I changed the code to use sizeof - but will wait for a response from Peter before changing the size. It's consistent throughout the sequence code to be 100 for this purpose. Rod Taylor <rbt@rbt.ca>
This commit is contained in:
parent
a00431b8d8
commit
8000fdd462
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.92 2003/03/20 03:34:55 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.93 2003/03/20 05:18:14 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -24,19 +24,6 @@
|
|||||||
#include "utils/acl.h"
|
#include "utils/acl.h"
|
||||||
#include "utils/builtins.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,
|
* 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
|
* so we pre-log a few fetches in advance. In the event of
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
* by PostgreSQL
|
* by PostgreSQL
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.319 2003/03/10 22:28:19 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.320 2003/03/20 05:18:14 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -52,6 +52,8 @@ int optreset;
|
|||||||
#include "catalog/pg_trigger.h"
|
#include "catalog/pg_trigger.h"
|
||||||
#include "catalog/pg_type.h"
|
#include "catalog/pg_type.h"
|
||||||
|
|
||||||
|
#include "commands/sequence.h"
|
||||||
|
|
||||||
#include "libpq-fe.h"
|
#include "libpq-fe.h"
|
||||||
#include "libpq/libpq-fs.h"
|
#include "libpq/libpq-fs.h"
|
||||||
|
|
||||||
@ -5986,9 +5988,11 @@ dumpOneSequence(Archive *fout, TableInfo *tbinfo,
|
|||||||
PGresult *res;
|
PGresult *res;
|
||||||
char *last,
|
char *last,
|
||||||
*incby,
|
*incby,
|
||||||
*maxv,
|
*maxv = NULL,
|
||||||
*minv,
|
*minv = NULL,
|
||||||
*cache;
|
*cache;
|
||||||
|
char bufm[100],
|
||||||
|
bufx[100];
|
||||||
bool cycled,
|
bool cycled,
|
||||||
called;
|
called;
|
||||||
PQExpBuffer query = createPQExpBuffer();
|
PQExpBuffer query = createPQExpBuffer();
|
||||||
@ -5997,9 +6001,21 @@ dumpOneSequence(Archive *fout, TableInfo *tbinfo,
|
|||||||
/* Make sure we are in proper schema */
|
/* Make sure we are in proper schema */
|
||||||
selectSourceSchema(tbinfo->relnamespace->nspname);
|
selectSourceSchema(tbinfo->relnamespace->nspname);
|
||||||
|
|
||||||
|
snprintf(bufm, sizeof(bufm), INT64_FORMAT, SEQ_MINVALUE);
|
||||||
|
snprintf(bufx, sizeof(bufx), INT64_FORMAT, SEQ_MAXVALUE);
|
||||||
|
|
||||||
appendPQExpBuffer(query,
|
appendPQExpBuffer(query,
|
||||||
"SELECT sequence_name, last_value, increment_by, max_value, "
|
"SELECT sequence_name, last_value, increment_by, "
|
||||||
"min_value, cache_value, is_cycled, is_called from %s",
|
"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));
|
fmtId(tbinfo->relname));
|
||||||
|
|
||||||
res = PQexec(g_conn, query->data);
|
res = PQexec(g_conn, query->data);
|
||||||
@ -6028,7 +6044,9 @@ dumpOneSequence(Archive *fout, TableInfo *tbinfo,
|
|||||||
|
|
||||||
last = PQgetvalue(res, 0, 1);
|
last = PQgetvalue(res, 0, 1);
|
||||||
incby = PQgetvalue(res, 0, 2);
|
incby = PQgetvalue(res, 0, 2);
|
||||||
|
if (!PQgetisnull(res, 0, 3))
|
||||||
maxv = PQgetvalue(res, 0, 3);
|
maxv = PQgetvalue(res, 0, 3);
|
||||||
|
if (!PQgetisnull(res, 0, 4))
|
||||||
minv = PQgetvalue(res, 0, 4);
|
minv = PQgetvalue(res, 0, 4);
|
||||||
cache = PQgetvalue(res, 0, 5);
|
cache = PQgetvalue(res, 0, 5);
|
||||||
cycled = (strcmp(PQgetvalue(res, 0, 6), "t") == 0);
|
cycled = (strcmp(PQgetvalue(res, 0, 6), "t") == 0);
|
||||||
@ -6060,12 +6078,23 @@ dumpOneSequence(Archive *fout, TableInfo *tbinfo,
|
|||||||
|
|
||||||
resetPQExpBuffer(query);
|
resetPQExpBuffer(query);
|
||||||
appendPQExpBuffer(query,
|
appendPQExpBuffer(query,
|
||||||
"CREATE SEQUENCE %s\n START %s\n INCREMENT %s\n"
|
"CREATE SEQUENCE %s\n START WITH %s\n INCREMENT BY %s\n",
|
||||||
" MAXVALUE %s\n MINVALUE %s\n CACHE %s%s;\n",
|
|
||||||
fmtId(tbinfo->relname),
|
fmtId(tbinfo->relname),
|
||||||
(called ? minv : last),
|
(called ? minv : last), incby);
|
||||||
incby, maxv, minv, cache,
|
|
||||||
(cycled ? "\n CYCLE" : ""));
|
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,
|
ArchiveEntry(fout, tbinfo->oid, tbinfo->relname,
|
||||||
tbinfo->relnamespace->nspname, tbinfo->usename,
|
tbinfo->relnamespace->nspname, tbinfo->usename,
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: sequence.h,v 1.21 2002/06/20 20:29:49 momjian Exp $
|
* $Id: sequence.h,v 1.22 2003/03/20 05:18:15 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -89,4 +89,17 @@ extern void seq_redo(XLogRecPtr lsn, XLogRecord *rptr);
|
|||||||
extern void seq_undo(XLogRecPtr lsn, XLogRecord *rptr);
|
extern void seq_undo(XLogRecPtr lsn, XLogRecord *rptr);
|
||||||
extern void seq_desc(char *buf, uint8 xl_info, char *rec);
|
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 */
|
#endif /* SEQUENCE_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user