Skip to content

Commit

Permalink
sql: compat: Support 'COMMENT ON TABLE foo is 'bar' parsing
Browse files Browse the repository at this point in the history
Many ORMs use Postgres' COMMENT statement to label database objects. This commit
handles the grammar changes necessary to support the COMMENT syntax for
Columns and Tables. The implementaiton of COMMENT is left for a future PR.

Release note (sql change): allow parsing of COMMENT ON syntax
  • Loading branch information
Zachary.smith authored and Zachary.smith committed Dec 27, 2017
1 parent 8f21ede commit a141427
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/codelabs/01-sql-statement.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ a method to the planner. That's where the centralized statement dispatch takes
place, so that's the place to add semantics.

Look for the source of the error we're seeing. You'll find that it's at the end
of a long type switch statement. Let's add a case to that:
of a long type switch statement in `/pkg/sql/plan.go`. Let's add a case to that:

```go
case *tree.Frobnicate:
Expand Down
24 changes: 23 additions & 1 deletion pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func (u *sqlSymUnion) scrubOption() tree.ScrubOption {

%token <str> CACHE CANCEL CASCADE CASE CAST CHAR
%token <str> CHARACTER CHARACTERISTICS CHECK
%token <str> CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMIT
%token <str> CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMIT
%token <str> COMMITTED COMPACT CONCAT CONFIGURATION CONFIGURATIONS CONFIGURE
%token <str> CONFLICT CONSTRAINT CONSTRAINTS CONTAINS COPY COVERING CREATE
%token <str> CROSS CSV CUBE CURRENT CURRENT_CATALOG CURRENT_DATE CURRENT_SCHEMA
Expand Down Expand Up @@ -590,6 +590,7 @@ func (u *sqlSymUnion) scrubOption() tree.ScrubOption {
%type <tree.ScrubOptions> scrub_option_list
%type <tree.ScrubOption> scrub_option

%type <tree.Statement> comment_stmt
%type <tree.Statement> commit_stmt
%type <tree.Statement> copy_from_stmt

Expand Down Expand Up @@ -671,6 +672,7 @@ func (u *sqlSymUnion) scrubOption() tree.ScrubOption {
%type <tree.Statement> show_zone_stmt

%type <str> session_var
%type <str> comment_text

%type <tree.Statement> transaction_stmt
%type <tree.Statement> truncate_stmt
Expand Down Expand Up @@ -994,6 +996,7 @@ stmt:
| cancel_stmt // help texts in sub-rule
| scrub_stmt
| copy_from_stmt
| comment_stmt // EXTEND WITH HELP: COMMENT
| create_stmt // help texts in sub-rule
| deallocate_stmt // EXTEND WITH HELP: DEALLOCATE
| delete_stmt // EXTEND WITH HELP: DELETE
Expand Down Expand Up @@ -1640,6 +1643,24 @@ cancel_query_stmt:
}
| CANCEL QUERY error // SHOW HELP: CANCEL QUERY

// %Help: COMMENT - add a comment to a database object
// %Category: Misc
// %Text:
// COMMENT ON [ COLUMN | TABLE ] <objname> IS { 'text' | NULL }
comment_stmt:
COMMENT ON TABLE any_name IS comment_text
{
return unimplemented(sqllex, "COMMENT ON TABLE unimplemented")
}
| COMMENT ON COLUMN any_name IS comment_text
{
return unimplemented(sqllex, "COMMENT ON COLUMN unimplemented")
}

comment_text:
SCONST { $$ = $1 }
| NULL { $$ = "" }

// %Help: CREATE
// %Category: Group
// %Text:
Expand Down Expand Up @@ -7068,6 +7089,7 @@ unreserved_keyword:
| CASCADE
| CLUSTER
| COLUMNS
| COMMENT
| COMMIT
| COMMITTED
| COMPACT
Expand Down

0 comments on commit a141427

Please sign in to comment.