|
53 | 53 | #include"pgstat.h"
|
54 | 54 | #include"utils/acl.h"
|
55 | 55 | #include"utils/builtins.h"
|
| 56 | +#include"utils/date.h" |
56 | 57 | #include"utils/lsyscache.h"
|
57 | 58 | #include"utils/memutils.h"
|
| 59 | +#include"utils/timestamp.h" |
58 | 60 | #include"utils/typcache.h"
|
59 | 61 | #include"utils/xml.h"
|
60 | 62 |
|
@@ -147,6 +149,9 @@ static Datum ExecEvalCoalesce(CoalesceExprState *coalesceExpr,
|
147 | 149 | staticDatumExecEvalMinMax(MinMaxExprState*minmaxExpr,
|
148 | 150 | ExprContext*econtext,
|
149 | 151 | bool*isNull,ExprDoneCond*isDone);
|
| 152 | +staticDatumExecEvalSQLValueFunction(ExprState*svfExpr, |
| 153 | +ExprContext*econtext, |
| 154 | +bool*isNull,ExprDoneCond*isDone); |
150 | 155 | staticDatumExecEvalXml(XmlExprState*xmlExpr,ExprContext*econtext,
|
151 | 156 | bool*isNull,ExprDoneCond*isDone);
|
152 | 157 | staticDatumExecEvalNullIf(FuncExprState*nullIfExpr,
|
@@ -3530,6 +3535,75 @@ ExecEvalMinMax(MinMaxExprState *minmaxExpr, ExprContext *econtext,
|
3530 | 3535 | returnresult;
|
3531 | 3536 | }
|
3532 | 3537 |
|
| 3538 | +/* ---------------------------------------------------------------- |
| 3539 | + *ExecEvalSQLValueFunction |
| 3540 | + * ---------------------------------------------------------------- |
| 3541 | + */ |
| 3542 | +staticDatum |
| 3543 | +ExecEvalSQLValueFunction(ExprState*svfExpr, |
| 3544 | +ExprContext*econtext, |
| 3545 | +bool*isNull,ExprDoneCond*isDone) |
| 3546 | +{ |
| 3547 | +Datumresult= (Datum)0; |
| 3548 | +SQLValueFunction*svf= (SQLValueFunction*)svfExpr->expr; |
| 3549 | +FunctionCallInfoDatafcinfo; |
| 3550 | + |
| 3551 | +if (isDone) |
| 3552 | +*isDone=ExprSingleResult; |
| 3553 | +*isNull= false; |
| 3554 | + |
| 3555 | +/* |
| 3556 | + * Note: current_schema() can return NULL. current_user() etc currently |
| 3557 | + * cannot, but might as well code those cases the same way for safety. |
| 3558 | + */ |
| 3559 | +switch (svf->op) |
| 3560 | +{ |
| 3561 | +caseSVFOP_CURRENT_DATE: |
| 3562 | +result=DateADTGetDatum(GetSQLCurrentDate()); |
| 3563 | +break; |
| 3564 | +caseSVFOP_CURRENT_TIME: |
| 3565 | +caseSVFOP_CURRENT_TIME_N: |
| 3566 | +result=TimeTzADTPGetDatum(GetSQLCurrentTime(svf->typmod)); |
| 3567 | +break; |
| 3568 | +caseSVFOP_CURRENT_TIMESTAMP: |
| 3569 | +caseSVFOP_CURRENT_TIMESTAMP_N: |
| 3570 | +result=TimestampTzGetDatum(GetSQLCurrentTimestamp(svf->typmod)); |
| 3571 | +break; |
| 3572 | +caseSVFOP_LOCALTIME: |
| 3573 | +caseSVFOP_LOCALTIME_N: |
| 3574 | +result=TimeADTGetDatum(GetSQLLocalTime(svf->typmod)); |
| 3575 | +break; |
| 3576 | +caseSVFOP_LOCALTIMESTAMP: |
| 3577 | +caseSVFOP_LOCALTIMESTAMP_N: |
| 3578 | +result=TimestampGetDatum(GetSQLLocalTimestamp(svf->typmod)); |
| 3579 | +break; |
| 3580 | +caseSVFOP_CURRENT_ROLE: |
| 3581 | +caseSVFOP_CURRENT_USER: |
| 3582 | +caseSVFOP_USER: |
| 3583 | +InitFunctionCallInfoData(fcinfo,NULL,0,InvalidOid,NULL,NULL); |
| 3584 | +result=current_user(&fcinfo); |
| 3585 | +*isNull=fcinfo.isnull; |
| 3586 | +break; |
| 3587 | +caseSVFOP_SESSION_USER: |
| 3588 | +InitFunctionCallInfoData(fcinfo,NULL,0,InvalidOid,NULL,NULL); |
| 3589 | +result=session_user(&fcinfo); |
| 3590 | +*isNull=fcinfo.isnull; |
| 3591 | +break; |
| 3592 | +caseSVFOP_CURRENT_CATALOG: |
| 3593 | +InitFunctionCallInfoData(fcinfo,NULL,0,InvalidOid,NULL,NULL); |
| 3594 | +result=current_database(&fcinfo); |
| 3595 | +*isNull=fcinfo.isnull; |
| 3596 | +break; |
| 3597 | +caseSVFOP_CURRENT_SCHEMA: |
| 3598 | +InitFunctionCallInfoData(fcinfo,NULL,0,InvalidOid,NULL,NULL); |
| 3599 | +result=current_schema(&fcinfo); |
| 3600 | +*isNull=fcinfo.isnull; |
| 3601 | +break; |
| 3602 | +} |
| 3603 | + |
| 3604 | +returnresult; |
| 3605 | +} |
| 3606 | + |
3533 | 3607 | /* ----------------------------------------------------------------
|
3534 | 3608 | *ExecEvalXml
|
3535 | 3609 | * ----------------------------------------------------------------
|
@@ -5086,6 +5160,10 @@ ExecInitExpr(Expr *node, PlanState *parent)
|
5086 | 5160 | state= (ExprState*)mstate;
|
5087 | 5161 | }
|
5088 | 5162 | break;
|
| 5163 | +caseT_SQLValueFunction: |
| 5164 | +state= (ExprState*)makeNode(ExprState); |
| 5165 | +state->evalfunc=ExecEvalSQLValueFunction; |
| 5166 | +break; |
5089 | 5167 | caseT_XmlExpr:
|
5090 | 5168 | {
|
5091 | 5169 | XmlExpr*xexpr= (XmlExpr*)node;
|
|