* transformLimitClause - * Transform the expression and make sure it is of type bigint. * Used for LIMIT and allied clauses. * * Note: as of Postgres 8.2, LIMIT expressions are expected to yield int8, * rather than int4 as before. * * constructName does not affect the semantics, but is used in error messages */
| 1964 | * constructName does not affect the semantics, but is used in error messages |
| 1965 | */ |
| 1966 | Node * |
| 1967 | transformLimitClause(ParseState *pstate, Node *clause, |
| 1968 | ParseExprKind exprKind, const char *constructName, |
| 1969 | LimitOption limitOption) |
| 1970 | { |
| 1971 | Node *qual; |
| 1972 | |
| 1973 | if (clause == NULL) |
| 1974 | return NULL; |
| 1975 | |
| 1976 | qual = transformExpr(pstate, clause, exprKind); |
| 1977 | |
| 1978 | qual = coerce_to_specific_type(pstate, qual, INT8OID, constructName); |
| 1979 | |
| 1980 | /* LIMIT can't refer to any variables of the current query */ |
| 1981 | checkExprIsVarFree(pstate, qual, constructName); |
| 1982 | |
| 1983 | /* |
| 1984 | * Don't allow NULLs in FETCH FIRST .. WITH TIES. This test is ugly and |
| 1985 | * extremely simplistic, in that you can pass a NULL anyway by hiding it |
| 1986 | * inside an expression -- but this protects ruleutils against emitting an |
| 1987 | * unadorned NULL that's not accepted back by the grammar. |
| 1988 | */ |
| 1989 | if (exprKind == EXPR_KIND_LIMIT && limitOption == LIMIT_OPTION_WITH_TIES && |
| 1990 | IsA(clause, A_Const) && ((A_Const *) clause)->val.type == T_Null) |
| 1991 | ereport(ERROR, |
| 1992 | (errcode(ERRCODE_INVALID_ROW_COUNT_IN_LIMIT_CLAUSE), |
| 1993 | errmsg("row count cannot be null in FETCH FIRST ... WITH TIES clause"))); |
| 1994 | |
| 1995 | return qual; |
| 1996 | } |
| 1997 | |
| 1998 | /* |
| 1999 | * checkExprIsVarFree |
no test coverage detected