|
24 | 24 | #include"commands/defrem.h" |
25 | 25 | #include"commands/sequence.h" |
26 | 26 | #include"commands/tablecmds.h" |
| 27 | +#include"funcapi.h" |
27 | 28 | #include"miscadmin.h" |
28 | 29 | #include"nodes/makefuncs.h" |
29 | 30 | #include"storage/bufmgr.h" |
@@ -1420,6 +1421,56 @@ process_owned_by(Relation seqrel, List *owned_by) |
1420 | 1421 | } |
1421 | 1422 |
|
1422 | 1423 |
|
| 1424 | +/* |
| 1425 | + * Return sequence parameters, for use by information schema |
| 1426 | + */ |
| 1427 | +Datum |
| 1428 | +pg_sequence_parameters(PG_FUNCTION_ARGS) |
| 1429 | +{ |
| 1430 | +Oidrelid=PG_GETARG_OID(0); |
| 1431 | +TupleDesctupdesc; |
| 1432 | +Datumvalues[5]; |
| 1433 | +boolisnull[5]; |
| 1434 | +SeqTableelm; |
| 1435 | +Relationseqrel; |
| 1436 | +Bufferbuf; |
| 1437 | +Form_pg_sequenceseq; |
| 1438 | + |
| 1439 | +/* open and AccessShareLock sequence */ |
| 1440 | +init_sequence(relid,&elm,&seqrel); |
| 1441 | + |
| 1442 | +if (pg_class_aclcheck(relid,GetUserId(),ACL_SELECT |ACL_UPDATE |ACL_USAGE)!=ACLCHECK_OK) |
| 1443 | +ereport(ERROR, |
| 1444 | +(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), |
| 1445 | +errmsg("permission denied for sequence %s", |
| 1446 | +RelationGetRelationName(seqrel)))); |
| 1447 | + |
| 1448 | +tupdesc=CreateTemplateTupleDesc(5, false); |
| 1449 | +TupleDescInitEntry(tupdesc, (AttrNumber)1,"start_value",INT8OID,-1,0); |
| 1450 | +TupleDescInitEntry(tupdesc, (AttrNumber)2,"minimum_value",INT8OID,-1,0); |
| 1451 | +TupleDescInitEntry(tupdesc, (AttrNumber)3,"maximum_value",INT8OID,-1,0); |
| 1452 | +TupleDescInitEntry(tupdesc, (AttrNumber)4,"increment",INT8OID,-1,0); |
| 1453 | +TupleDescInitEntry(tupdesc, (AttrNumber)5,"cycle_option",BOOLOID,-1,0); |
| 1454 | + |
| 1455 | +BlessTupleDesc(tupdesc); |
| 1456 | + |
| 1457 | +memset(isnull,0,sizeof(isnull)); |
| 1458 | + |
| 1459 | +seq=read_info(elm,seqrel,&buf); |
| 1460 | + |
| 1461 | +values[0]=Int64GetDatum(seq->start_value); |
| 1462 | +values[1]=Int64GetDatum(seq->min_value); |
| 1463 | +values[2]=Int64GetDatum(seq->max_value); |
| 1464 | +values[3]=Int64GetDatum(seq->increment_by); |
| 1465 | +values[4]=BoolGetDatum(seq->is_cycled); |
| 1466 | + |
| 1467 | +UnlockReleaseBuffer(buf); |
| 1468 | +relation_close(seqrel,NoLock); |
| 1469 | + |
| 1470 | +returnHeapTupleGetDatum(heap_form_tuple(tupdesc,values,isnull)); |
| 1471 | +} |
| 1472 | + |
| 1473 | + |
1423 | 1474 | void |
1424 | 1475 | seq_redo(XLogRecPtrlsn,XLogRecord*record) |
1425 | 1476 | { |
|