*** pgsql/src/backend/parser/gram.y 2008/12/04 11:42:24 2.642 --- pgsql/src/backend/parser/gram.y 2008/12/04 17:51:26 2.643 *************** *** 11,17 **** * * * IDENTIFICATION ! * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.641 2008/11/26 08:45:11 petere Exp $ * * HISTORY * AUTHOR DATE MAJOR EVENT --- 11,17 ---- * * * IDENTIFICATION ! * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.642 2008/12/04 11:42:24 heikki Exp $ * * HISTORY * AUTHOR DATE MAJOR EVENT *************** static TypeName *TableFuncTypeName(List *** 255,260 **** --- 255,261 ---- %type stmtblock stmtmulti OptTableElementList TableElementList OptInherit definition OptWith opt_distinct opt_definition func_args func_args_list + func_args_with_defaults func_args_with_defaults_list func_as createfunc_opt_list alterfunc_opt_list aggr_args old_aggr_definition old_aggr_list oper_argtypes RuleActionList RuleActionMulti *************** static TypeName *TableFuncTypeName(List *** 278,284 **** %type into_clause create_as_target %type createfunc_opt_item common_func_opt_item ! %type func_arg table_func_column %type arg_class %type func_return func_type --- 279,285 ---- %type into_clause create_as_target %type createfunc_opt_item common_func_opt_item ! %type func_arg func_arg_with_default table_func_column %type arg_class %type func_return func_type *************** opt_nulls_order: NULLS_FIRST { $$ = S *** 4170,4176 **** *****************************************************************************/ CreateFunctionStmt: ! CREATE opt_or_replace FUNCTION func_name func_args RETURNS func_return createfunc_opt_list opt_definition { CreateFunctionStmt *n = makeNode(CreateFunctionStmt); --- 4171,4177 ---- *****************************************************************************/ CreateFunctionStmt: ! CREATE opt_or_replace FUNCTION func_name func_args_with_defaults RETURNS func_return createfunc_opt_list opt_definition { CreateFunctionStmt *n = makeNode(CreateFunctionStmt); *************** CreateFunctionStmt: *** 4182,4188 **** n->withClause = $9; $$ = (Node *)n; } ! | CREATE opt_or_replace FUNCTION func_name func_args RETURNS TABLE '(' table_func_column_list ')' createfunc_opt_list opt_definition { CreateFunctionStmt *n = makeNode(CreateFunctionStmt); --- 4183,4189 ---- n->withClause = $9; $$ = (Node *)n; } ! | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults RETURNS TABLE '(' table_func_column_list ')' createfunc_opt_list opt_definition { CreateFunctionStmt *n = makeNode(CreateFunctionStmt); *************** CreateFunctionStmt: *** 4195,4201 **** n->withClause = $12; $$ = (Node *)n; } ! | CREATE opt_or_replace FUNCTION func_name func_args createfunc_opt_list opt_definition { CreateFunctionStmt *n = makeNode(CreateFunctionStmt); --- 4196,4202 ---- n->withClause = $12; $$ = (Node *)n; } ! | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults createfunc_opt_list opt_definition { CreateFunctionStmt *n = makeNode(CreateFunctionStmt); *************** func_args_list: *** 4224,4229 **** --- 4225,4245 ---- ; /* + * func_args_with_defaults is separate because we only want to accept + * defaults in CREATE FUNCTION, not in ALTER etc. + */ + func_args_with_defaults: + '(' func_args_with_defaults_list ')' { $$ = $2; } + | '(' ')' { $$ = NIL; } + ; + + func_args_with_defaults_list: + func_arg_with_default { $$ = list_make1( $1); } + | func_args_with_defaults_list ',' func_arg_with_default { $$ = lappend($1, $3); } + ; + + + /* * The style with arg_class first is SQL99 standard, but Oracle puts * param_name first; accept both since it's likely people will try both * anyway. Don't bother trying to save productions by letting arg_class *************** func_arg: *** 4240,4245 **** --- 4256,4262 ---- n->name = $2; n->argType = $3; n->mode = $1; + n->defexpr = NULL; $$ = n; } | param_name arg_class func_type *************** func_arg: *** 4248,4253 **** --- 4265,4271 ---- n->name = $1; n->argType = $3; n->mode = $2; + n->defexpr = NULL; $$ = n; } | param_name func_type *************** func_arg: *** 4256,4261 **** --- 4274,4280 ---- n->name = $1; n->argType = $2; n->mode = FUNC_PARAM_IN; + n->defexpr = NULL; $$ = n; } | arg_class func_type *************** func_arg: *** 4264,4269 **** --- 4283,4289 ---- n->name = NULL; n->argType = $2; n->mode = $1; + n->defexpr = NULL; $$ = n; } | func_type *************** func_arg: *** 4272,4277 **** --- 4292,4298 ---- n->name = NULL; n->argType = $1; n->mode = FUNC_PARAM_IN; + n->defexpr = NULL; $$ = n; } ; *************** func_type: Typename { $$ = $1; } *** 4322,4327 **** --- 4343,4365 ---- } ; + func_arg_with_default: + func_arg + { + $$ = $1; + } + | func_arg DEFAULT a_expr + { + $$ = $1; + $$->defexpr = $3; + } + | func_arg '=' a_expr + { + $$ = $1; + $$->defexpr = $3; + } + ; + createfunc_opt_list: /* Must be at least one to prevent conflict */