Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6fec216

Browse files
committed
Added new SQL function setval(seq,val,bool) to restore is_called as well as value
(will be used in a future pg_dump).
1 parent8e72a87 commit6fec216

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

‎src/backend/commands/sequence.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ static SeqTable init_sequence(char *caller, char *name);
6161
staticForm_pg_sequenceread_info(char*caller,SeqTableelm,Buffer*buf);
6262
staticvoidinit_params(CreateSeqStmt*seq,Form_pg_sequencenew);
6363
staticintget_param(DefElem*def);
64+
staticvoiddo_setval(char*seqname,int32next,chariscalled);
6465

6566
/*
6667
* DefineSequence
@@ -317,12 +318,9 @@ currval(PG_FUNCTION_ARGS)
317318
PG_RETURN_INT32(result);
318319
}
319320

320-
Datum
321-
setval(PG_FUNCTION_ARGS)
321+
staticvoid
322+
do_setval(char*seqname,int32next,booliscalled)
322323
{
323-
text*seqin=PG_GETARG_TEXT_P(0);
324-
int32next=PG_GETARG_INT32(1);
325-
char*seqname=get_seq_name(seqin);
326324
SeqTableelm;
327325
Bufferbuf;
328326
Form_pg_sequenceseq;
@@ -356,7 +354,7 @@ setval(PG_FUNCTION_ARGS)
356354

357355
/* save info in sequence relation */
358356
seq->last_value=next;/* last fetched number */
359-
seq->is_called='t';
357+
seq->is_called=iscalled ?'t' :'f';
360358

361359
LockBuffer(buf,BUFFER_LOCK_UNLOCK);
362360

@@ -365,6 +363,30 @@ setval(PG_FUNCTION_ARGS)
365363

366364
pfree(seqname);
367365

366+
}
367+
368+
Datum
369+
setval(PG_FUNCTION_ARGS)
370+
{
371+
text*seqin=PG_GETARG_TEXT_P(0);
372+
int32next=PG_GETARG_INT32(1);
373+
char*seqname=get_seq_name(seqin);
374+
375+
do_setval(seqname,next, true);
376+
377+
PG_RETURN_INT32(next);
378+
}
379+
380+
Datum
381+
setval_and_iscalled(PG_FUNCTION_ARGS)
382+
{
383+
text*seqin=PG_GETARG_TEXT_P(0);
384+
int32next=PG_GETARG_INT32(1);
385+
booliscalled=PG_GETARG_BOOL(2);
386+
char*seqname=get_seq_name(seqin);
387+
388+
do_setval(seqname,next,iscalled);
389+
368390
PG_RETURN_INT32(next);
369391
}
370392

‎src/include/catalog/pg_proc.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_proc.h,v 1.168 2000/09/25 12:58:47 momjian Exp $
10+
* $Id: pg_proc.h,v 1.169 2000/10/11 15:31:13 pjw Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -1978,6 +1978,8 @@ DATA(insert OID = 1575 ( currvalPGUID 12 f t f t 1 f 23 "25" 100 0 0 100cur
19781978
DESCR("sequence current value");
19791979
DATA(insertOID=1576 (setvalPGUID12ftft2f23"25 23"10000100setval- ));
19801980
DESCR("set sequence value");
1981+
DATA(insertOID=1765 (setvalPGUID12ftft3f23"25 23 16"10000100setval_and_iscalled- ));
1982+
DESCR("set sequence value and iscalled status");
19811983

19821984
DATA(insertOID=1579 (varbit_inPGUID12fttt1f1562"0"10000100varbit_in- ));
19831985
DESCR("(internal)");

‎src/include/commands/sequence.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
externDatumnextval(PG_FUNCTION_ARGS);
3131
externDatumcurrval(PG_FUNCTION_ARGS);
3232
externDatumsetval(PG_FUNCTION_ARGS);
33+
externDatumsetval_and_iscalled(PG_FUNCTION_ARGS);
3334

3435
externvoidDefineSequence(CreateSeqStmt*stmt);
3536
externvoidCloseSequences(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp