mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Oracle like currval behaviour.
This commit is contained in:
@ -204,6 +204,7 @@ nextval (struct varlena * seqin)
|
|||||||
|
|
||||||
/* open and WIntentLock sequence */
|
/* open and WIntentLock sequence */
|
||||||
elm = init_sequence ("nextval", seqname);
|
elm = init_sequence ("nextval", seqname);
|
||||||
|
pfree (seqname);
|
||||||
|
|
||||||
if ( elm->last != elm->cached ) /* some numbers were cached */
|
if ( elm->last != elm->cached ) /* some numbers were cached */
|
||||||
{
|
{
|
||||||
@ -237,7 +238,7 @@ nextval (struct varlena * seqin)
|
|||||||
break; /* stop caching */
|
break; /* stop caching */
|
||||||
if ( seq->is_cycled != 't' )
|
if ( seq->is_cycled != 't' )
|
||||||
elog (WARN, "%s.nextval: got MAXVALUE (%d)",
|
elog (WARN, "%s.nextval: got MAXVALUE (%d)",
|
||||||
seqname, maxv);
|
elm->name, maxv);
|
||||||
next = minv;
|
next = minv;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -252,7 +253,7 @@ nextval (struct varlena * seqin)
|
|||||||
break; /* stop caching */
|
break; /* stop caching */
|
||||||
if ( seq->is_cycled != 't' )
|
if ( seq->is_cycled != 't' )
|
||||||
elog (WARN, "%s.nextval: got MINVALUE (%d)",
|
elog (WARN, "%s.nextval: got MINVALUE (%d)",
|
||||||
seqname, minv);
|
elm->name, minv);
|
||||||
next = maxv;
|
next = maxv;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -287,33 +288,18 @@ currval (struct varlena * seqin)
|
|||||||
{
|
{
|
||||||
char *seqname = textout(seqin);
|
char *seqname = textout(seqin);
|
||||||
SeqTable elm;
|
SeqTable elm;
|
||||||
Buffer buf;
|
|
||||||
SequenceTupleForm seq;
|
|
||||||
ItemPointerData iptr;
|
|
||||||
int4 result;
|
int4 result;
|
||||||
|
|
||||||
/* open and WIntentLock sequence */
|
/* open and WIntentLock sequence */
|
||||||
elm = init_sequence ("currval", seqname);
|
elm = init_sequence ("currval", seqname);
|
||||||
|
pfree (seqname);
|
||||||
|
|
||||||
if ( elm->last != elm->cached ) /* some numbers were cached */
|
if ( elm->increment == 0 ) /* nextval/read_info were not called */
|
||||||
{
|
{
|
||||||
return (elm->last); /* return last returned by nextval */
|
elog (WARN, "%s.currval is not yet defined in this session", elm->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
seq = read_info ("currval", elm, &buf);
|
result = elm->last;
|
||||||
|
|
||||||
if ( seq->is_called != 't' )
|
|
||||||
{
|
|
||||||
elog (WARN, "%s.currval: yet undefined (%s.nextval never called)",
|
|
||||||
seqname, seqname);
|
|
||||||
}
|
|
||||||
result = seq->last_value;
|
|
||||||
|
|
||||||
if ( ReleaseBuffer (buf) == STATUS_ERROR )
|
|
||||||
elog (WARN, "%s.currval: ReleaseBuffer failed", seqname);
|
|
||||||
|
|
||||||
ItemPointerSet(&iptr, 0, FirstOffsetNumber);
|
|
||||||
RelationUnsetSingleWLockPage (elm->rel, &iptr);
|
|
||||||
|
|
||||||
return (result);
|
return (result);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user