1997-04-02 05:23:38 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* sequence.h
|
1997-09-07 07:04:48 +02:00
|
|
|
* prototypes for sequence.c.
|
1997-04-02 05:23:38 +02:00
|
|
|
*
|
2003-08-04 04:40:20 +02:00
|
|
|
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
2001-08-16 22:38:56 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
2003-08-04 04:40:20 +02:00
|
|
|
* $Id: sequence.h,v 1.25 2003/08/04 02:40:13 momjian Exp $
|
1997-04-02 05:23:38 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef SEQUENCE_H
|
|
|
|
#define SEQUENCE_H
|
|
|
|
|
1997-11-26 02:14:33 +01:00
|
|
|
#include "nodes/parsenodes.h"
|
2000-11-30 02:47:33 +01:00
|
|
|
#include "access/xlog.h"
|
|
|
|
|
2001-08-16 22:38:56 +02:00
|
|
|
/*
|
|
|
|
* On a machine with no 64-bit-int C datatype, sizeof(int64) will not be 8,
|
|
|
|
* but we need this struct type to line up with the way that a sequence
|
|
|
|
* table is defined --- and pg_type will say that int8 is 8 bytes anyway.
|
|
|
|
* So, we need padding. Ugly but necessary.
|
|
|
|
*/
|
2000-11-30 02:47:33 +01:00
|
|
|
typedef struct FormData_pg_sequence
|
|
|
|
{
|
|
|
|
NameData sequence_name;
|
2001-08-16 22:38:56 +02:00
|
|
|
#ifndef INT64_IS_BUSTED
|
|
|
|
int64 last_value;
|
|
|
|
int64 increment_by;
|
|
|
|
int64 max_value;
|
|
|
|
int64 min_value;
|
|
|
|
int64 cache_value;
|
|
|
|
int64 log_cnt;
|
|
|
|
#else
|
2001-01-23 02:48:17 +01:00
|
|
|
int32 last_value;
|
2001-08-16 22:38:56 +02:00
|
|
|
int32 pad1;
|
2001-01-23 02:48:17 +01:00
|
|
|
int32 increment_by;
|
2001-08-16 22:38:56 +02:00
|
|
|
int32 pad2;
|
2001-01-23 02:48:17 +01:00
|
|
|
int32 max_value;
|
2001-08-16 22:38:56 +02:00
|
|
|
int32 pad3;
|
2001-01-23 02:48:17 +01:00
|
|
|
int32 min_value;
|
2001-08-16 22:38:56 +02:00
|
|
|
int32 pad4;
|
2001-01-23 02:48:17 +01:00
|
|
|
int32 cache_value;
|
2001-08-16 22:38:56 +02:00
|
|
|
int32 pad5;
|
2001-01-23 02:48:17 +01:00
|
|
|
int32 log_cnt;
|
2001-08-16 22:38:56 +02:00
|
|
|
int32 pad6;
|
|
|
|
#endif
|
|
|
|
bool is_cycled;
|
|
|
|
bool is_called;
|
2000-11-30 02:47:33 +01:00
|
|
|
} FormData_pg_sequence;
|
|
|
|
|
|
|
|
typedef FormData_pg_sequence *Form_pg_sequence;
|
1997-11-26 02:14:33 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
2000-06-11 22:08:01 +02:00
|
|
|
* Columns of a sequence relation
|
1997-04-02 05:23:38 +02:00
|
|
|
*/
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
#define SEQ_COL_NAME 1
|
|
|
|
#define SEQ_COL_LASTVAL 2
|
|
|
|
#define SEQ_COL_INCBY 3
|
|
|
|
#define SEQ_COL_MAXVALUE 4
|
|
|
|
#define SEQ_COL_MINVALUE 5
|
|
|
|
#define SEQ_COL_CACHE 6
|
2001-03-22 05:01:46 +01:00
|
|
|
#define SEQ_COL_LOG 7
|
2000-11-30 02:47:33 +01:00
|
|
|
#define SEQ_COL_CYCLE 8
|
|
|
|
#define SEQ_COL_CALLED 9
|
1997-04-02 05:23:38 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
#define SEQ_COL_FIRSTCOL SEQ_COL_NAME
|
|
|
|
#define SEQ_COL_LASTCOL SEQ_COL_CALLED
|
1997-04-02 05:23:38 +02:00
|
|
|
|
2000-11-30 02:47:33 +01:00
|
|
|
/* XLOG stuff */
|
2001-03-22 05:01:46 +01:00
|
|
|
#define XLOG_SEQ_LOG 0x00
|
2000-11-30 02:47:33 +01:00
|
|
|
|
|
|
|
typedef struct xl_seq_rec
|
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
RelFileNode node;
|
2000-12-28 14:00:29 +01:00
|
|
|
/* SEQUENCE TUPLE DATA FOLLOWS AT THE END */
|
2000-11-30 02:47:33 +01:00
|
|
|
} xl_seq_rec;
|
|
|
|
|
2000-06-11 22:08:01 +02:00
|
|
|
extern Datum nextval(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum currval(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum setval(PG_FUNCTION_ARGS);
|
2000-10-11 17:31:34 +02:00
|
|
|
extern Datum setval_and_iscalled(PG_FUNCTION_ARGS);
|
2000-06-11 22:08:01 +02:00
|
|
|
|
1997-09-08 23:56:23 +02:00
|
|
|
extern void DefineSequence(CreateSeqStmt *stmt);
|
2003-08-04 02:43:34 +02:00
|
|
|
extern void AlterSequence(AlterSeqStmt * stmt);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-11-30 02:47:33 +01:00
|
|
|
extern void seq_redo(XLogRecPtr lsn, XLogRecord *rptr);
|
|
|
|
extern void seq_undo(XLogRecPtr lsn, XLogRecord *rptr);
|
2001-03-22 05:01:46 +01:00
|
|
|
extern void seq_desc(char *buf, uint8 xl_info, char *rec);
|
2001-10-28 07:26:15 +01: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>
2003-03-20 06:18:15 +01:00
|
|
|
/* 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)
|
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* SEQUENCE_H */
|