Skip to content

Commit

Permalink
add OUT and INOUT argmode for routines
Browse files Browse the repository at this point in the history
  • Loading branch information
jennifersp committed Apr 4, 2024
1 parent 909aecc commit 064f179
Show file tree
Hide file tree
Showing 30 changed files with 73,181 additions and 71,933 deletions.
53 changes: 28 additions & 25 deletions postgres/parser/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ func (u *sqlSymUnion) aggregatesToDrop() []tree.AggregateToDrop {
%token <str> IF IFERROR IFNULL IGNORE_FOREIGN_KEYS ILIKE IMMEDIATE IMMUTABLE IMPORT
%token <str> IN INCLUDE INCLUDING INCREMENT INCREMENTAL INET INET_CONTAINED_BY_OR_EQUALS
%token <str> INET_CONTAINS_OR_EQUALS INDEX INDEXES INHERIT INHERITS INITCOND INJECT INLINE INPUT INTERLEAVE INITIALLY
%token <str> INNER INSERT INSTEAD INT INTEGER INTERNALLENGTH
%token <str> INNER INOUT INSERT INSTEAD INT INTEGER INTERNALLENGTH
%token <str> INTERSECT INTERVAL INTO INTO_DB INVERTED INVOKER IS ISERROR ISNULL ISOLATION IS_TEMPLATE

%token <str> JOB JOBS JOIN JSON JSONB JSON_SOME_EXISTS JSON_ALL_EXISTS
Expand Down Expand Up @@ -1296,7 +1296,7 @@ func (u *sqlSymUnion) aggregatesToDrop() []tree.AggregateToDrop {
%type <tree.Expr> string_or_placeholder
%type <tree.Expr> string_or_placeholder_list

%type <str> unreserved_keyword type_func_name_keyword type_func_name_no_crdb_extra_keyword type_func_name_crdb_extra_keyword
%type <str> unreserved_keyword type_func_name_keyword type_func_name_no_crdb_extra_keyword
%type <str> col_name_keyword reserved_keyword cockroachdb_extra_reserved_keyword extra_var_value

%type <tree.ResolvableTypeReference> complex_type_name
Expand Down Expand Up @@ -2842,27 +2842,43 @@ routine_arg_list:
routine_arg:
typename
{
$$.val = &tree.RoutineArg{Mode: "IN", Type: $1.typeReference()}
$$.val = &tree.RoutineArg{Mode: tree.RoutineArgModeIn, Type: $1.typeReference()}
}
| type_function_name typename
{
$$.val = &tree.RoutineArg{Mode: "IN", Name: tree.Name($1), Type: $2.typeReference()}
$$.val = &tree.RoutineArg{Mode: tree.RoutineArgModeIn, Name: tree.Name($1), Type: $2.typeReference()}
}
| IN typename
{
$$.val = &tree.RoutineArg{Mode: $1, Type: $2.typeReference()}
$$.val = &tree.RoutineArg{Mode: tree.RoutineArgModeIn, Type: $2.typeReference()}
}
| VARIADIC typename
| IN type_function_name typename
{
$$.val = &tree.RoutineArg{Mode: $1, Type: $2.typeReference()}
$$.val = &tree.RoutineArg{Mode: tree.RoutineArgModeIn, Name: tree.Name($2), Type: $3.typeReference()}
}
| IN type_function_name typename
| VARIADIC typename
{
$$.val = &tree.RoutineArg{Mode: $1, Name: tree.Name($2), Type: $3.typeReference()}
$$.val = &tree.RoutineArg{Mode: tree.RoutineArgModeVariadic, Type: $2.typeReference()}
}
| VARIADIC type_function_name typename
{
$$.val = &tree.RoutineArg{Mode: $1, Name: tree.Name($2), Type: $3.typeReference()}
$$.val = &tree.RoutineArg{Mode: tree.RoutineArgModeVariadic, Name: tree.Name($2), Type: $3.typeReference()}
}
| OUT typename
{
$$.val = &tree.RoutineArg{Mode: tree.RoutineArgModeOut, Type: $2.typeReference()}
}
| OUT type_function_name typename
{
$$.val = &tree.RoutineArg{Mode: tree.RoutineArgModeOut, Name: tree.Name($2), Type: $3.typeReference()}
}
| INOUT typename
{
$$.val = &tree.RoutineArg{Mode: tree.RoutineArgModeInout, Type: $2.typeReference()}
}
| INOUT type_function_name typename
{
$$.val = &tree.RoutineArg{Mode: tree.RoutineArgModeInout, Name: tree.Name($2), Type: $3.typeReference()}
}
alter_collation_stmt:
Expand Down Expand Up @@ -13760,7 +13776,6 @@ complex_db_object_name:
// trying to gain them back here.
db_object_name_component:
name
| type_func_name_crdb_extra_keyword
| cockroachdb_extra_reserved_keyword

// General name --- names that can be column, table, etc names.
Expand Down Expand Up @@ -13944,6 +13959,7 @@ unreserved_keyword:
| EXTENDED
| EXTENSION
| EXTERNAL
| FAMILY
| FILES
| FILTER
| FINALFUNC
Expand Down Expand Up @@ -14306,6 +14322,7 @@ col_name_keyword:
| IF
| IFERROR
| IFNULL
| INOUT
| INT
| INTEGER
| INTERVAL
Expand Down Expand Up @@ -14341,7 +14358,6 @@ col_name_keyword:
// type_func_name_keyword's along with the set of CRDB extensions.
type_func_name_keyword:
type_func_name_no_crdb_extra_keyword
| type_func_name_crdb_extra_keyword

// Type/function identifier --- keywords that can be type or function names.
//
Expand All @@ -14354,8 +14370,6 @@ type_func_name_keyword:
// - thomas 2000-11-28
//
// *** DO NOT ADD COCKROACHDB-SPECIFIC KEYWORDS HERE ***
//
// See type_func_name_crdb_extra_keyword below.
type_func_name_no_crdb_extra_keyword:
AUTHORIZATION
| COLLATION
Expand All @@ -14376,17 +14390,6 @@ type_func_name_no_crdb_extra_keyword:
| RIGHT
| SIMILAR

// CockroachDB-specific keywords that can be used in type/function
// identifiers.
//
// *** REFRAIN FROM ADDING KEYWORDS HERE ***
//
// Adding keywords here creates non-resolvable incompatibilities with
// postgres clients.
//
type_func_name_crdb_extra_keyword:
FAMILY

// Reserved keyword --- these keywords are usable only as a unrestricted_name.
//
// Keywords appear here if they could not be distinguished from variable, type,
Expand Down
30 changes: 25 additions & 5 deletions postgres/parser/sem/tree/create_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type RoutineArgs []*RoutineArg

// RoutineArg represents a routine argument. It can be used by FUNCTIONs and PROCEDUREs.
type RoutineArg struct {
Mode string
Mode RoutineArgMode
Name Name
Type ResolvableTypeReference
Default Expr
Expand All @@ -85,10 +85,8 @@ func (node RoutineArgs) Format(ctx *FmtCtx) {
if i != 0 {
ctx.WriteString(", ")
}
if t.Mode != "" {
ctx.WriteString(t.Mode)
ctx.WriteByte(' ')
}
ctx.FormatNode(&t.Mode)
ctx.WriteByte(' ')
if t.Name != "" {
ctx.FormatNode(&t.Name)
ctx.WriteByte(' ')
Expand All @@ -97,6 +95,28 @@ func (node RoutineArgs) Format(ctx *FmtCtx) {
}
}

type RoutineArgMode int8

const (
RoutineArgModeIn RoutineArgMode = iota
RoutineArgModeVariadic
RoutineArgModeOut
RoutineArgModeInout
)

func (node *RoutineArgMode) Format(ctx *FmtCtx) {
switch *node {
case RoutineArgModeIn:
ctx.WriteString("IN")
case RoutineArgModeVariadic:
ctx.WriteString("VARIADIC")
case RoutineArgModeOut:
ctx.WriteString("OUT")
case RoutineArgModeInout:
ctx.WriteString("INOUT")
}
}

type FunctionOption int8

const (
Expand Down
3 changes: 2 additions & 1 deletion testing/generation/command_docs/custom_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import (
// and there isn't a more specific definition in PrefixCustomVariables.
var GlobalCustomVariables = map[string]utils.StatementGenerator{
"access_method_type": customDefinition(`TABLE | INDEX`),
"argmode": customDefinition(`IN | VARIADIC`),
"agg_argmode": customDefinition(`IN | VARIADIC`),
"routine_argmode": customDefinition(`IN | VARIADIC | OUT | INOUT`),
"argtype": customDefinition(`FLOAT8`),
"boolean": customDefinition(`true`),
"cache": customDefinition(`1`),
Expand Down
Loading

0 comments on commit 064f179

Please sign in to comment.