1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-29 10:41:53 +03:00

Improve parsetree representation of special functions such as CURRENT_DATE.

We implement a dozen or so parameterless functions that the SQL standard
defines special syntax for.  Up to now, that was done by converting them
into more or less ad-hoc constructs such as "'now'::text::date".  That's
messy for multiple reasons: it exposes what should be implementation
details to users, and performance is worse than it needs to be in several
cases.  To improve matters, invent a new expression node type
SQLValueFunction that can represent any of these parameterless functions.

Bump catversion because this changes stored parsetrees for rules.

Discussion: <30058.1463091294@sss.pgh.pa.us>
This commit is contained in:
Tom Lane
2016-08-16 20:33:01 -04:00
parent 4bc4cfe3bd
commit 0bb51aa967
24 changed files with 626 additions and 168 deletions

View File

@ -1761,6 +1761,49 @@ FigureColnameInternal(Node *node, char **name)
return 2;
}
break;
case T_SQLValueFunction:
/* make these act like a function or variable */
switch (((SQLValueFunction *) node)->op)
{
case SVFOP_CURRENT_DATE:
*name = "current_date";
return 2;
case SVFOP_CURRENT_TIME:
case SVFOP_CURRENT_TIME_N:
*name = "current_time";
return 2;
case SVFOP_CURRENT_TIMESTAMP:
case SVFOP_CURRENT_TIMESTAMP_N:
*name = "current_timestamp";
return 2;
case SVFOP_LOCALTIME:
case SVFOP_LOCALTIME_N:
*name = "localtime";
return 2;
case SVFOP_LOCALTIMESTAMP:
case SVFOP_LOCALTIMESTAMP_N:
*name = "localtimestamp";
return 2;
case SVFOP_CURRENT_ROLE:
*name = "current_role";
return 2;
case SVFOP_CURRENT_USER:
*name = "current_user";
return 2;
case SVFOP_USER:
*name = "user";
return 2;
case SVFOP_SESSION_USER:
*name = "session_user";
return 2;
case SVFOP_CURRENT_CATALOG:
*name = "current_catalog";
return 2;
case SVFOP_CURRENT_SCHEMA:
*name = "current_schema";
return 2;
}
break;
case T_XmlExpr:
/* make SQL/XML functions act like a regular function */
switch (((XmlExpr *) node)->op)