Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
523 changes: 456 additions & 67 deletions postgres/parser/parser/sql.y

Large diffs are not rendered by default.

48 changes: 10 additions & 38 deletions postgres/parser/sem/tree/alter_aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

package tree

import "strings"

var _ Statement = &AlterAggregate{}

// AlterAggregate represents a ALTER AGGREGATE statement.
Expand All @@ -41,7 +39,7 @@ type AlterAggregate struct {
func (node *AlterAggregate) Format(ctx *FmtCtx) {
ctx.WriteString("ALTER AGGREGATE ")
ctx.FormatNode(&node.Name)
ctx.WriteString(" (")
ctx.WriteString(" ( ")
node.AggSig.Format(ctx)
ctx.WriteString(" )")

Expand All @@ -59,48 +57,22 @@ func (node *AlterAggregate) Format(ctx *FmtCtx) {

// AggregateSignature represents an aggregate_signature clause.
type AggregateSignature struct {
All bool
Arg *AggregateArg
OrderBy *AggregateArg
All bool
Args RoutineArgs
OrderByArgs RoutineArgs
}

// Format implements the NodeFormatter interface.
func (node *AggregateSignature) Format(ctx *FmtCtx) {
if node.All {
ctx.WriteString(" * ")
ctx.WriteString("* ")
} else {
if node.Arg != nil {
ctx.WriteByte(' ')
node.Arg.Format(ctx)
if len(node.Args) != 0 {
node.Args.Format(ctx)
}
if node.OrderBy != nil {
ctx.WriteString(" ORDER BY ")
node.Arg.Format(ctx)
if len(node.OrderByArgs) != 0 {
ctx.WriteString("ORDER BY ")
node.OrderByArgs.Format(ctx)
}
}
}

// AggregateArg represents an aggregate argument(s).
type AggregateArg struct {
Mode string
Name Name
Types []ResolvableTypeReference
}

// Format implements the NodeFormatter interface.
func (node *AggregateArg) Format(ctx *FmtCtx) {
ctx.WriteString(node.Mode)
if node.Name != "" {
ctx.WriteByte(' ')
ctx.FormatNode(&node.Name)
}
types := make([]string, len(node.Types))
for i, t := range node.Types {
types[i] = t.SQLString()
}

if len(types) > 0 {
ctx.WriteByte(' ')
ctx.WriteString(strings.Join(types, ", "))
}
}
119 changes: 119 additions & 0 deletions postgres/parser/sem/tree/comment_on.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Copyright 2023 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Copyright 2018 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package tree

import "github.com/dolthub/doltgresql/postgres/parser/lex"

// TODO: maybe combine all of COMMENT ON ... objects below into single CommentOn interface.

// CommentOnColumn represents an COMMENT ON COLUMN statement.
type CommentOnColumn struct {
*ColumnItem
Comment *string
}

// Format implements the NodeFormatter interface.
func (n *CommentOnColumn) Format(ctx *FmtCtx) {
ctx.WriteString("COMMENT ON COLUMN ")
ctx.FormatNode(n.ColumnItem)
ctx.WriteString(" IS ")
if n.Comment != nil {
lex.EncodeSQLStringWithFlags(&ctx.Buffer, *n.Comment, ctx.flags.EncodeFlags())
} else {
ctx.WriteString("NULL")
}
}

// CommentOnDatabase represents an COMMENT ON DATABASE statement.
type CommentOnDatabase struct {
Name Name
Comment *string
}

// Format implements the NodeFormatter interface.
func (n *CommentOnDatabase) Format(ctx *FmtCtx) {
ctx.WriteString("COMMENT ON DATABASE ")
ctx.FormatNode(&n.Name)
ctx.WriteString(" IS ")
if n.Comment != nil {
lex.EncodeSQLStringWithFlags(&ctx.Buffer, *n.Comment, ctx.flags.EncodeFlags())
} else {
ctx.WriteString("NULL")
}
}

// CommentOnExtension represents an COMMENT ON EXTENSION statement.
type CommentOnExtension struct {
Name Name
Comment *string
}

// Format implements the NodeFormatter interface.
func (n *CommentOnExtension) Format(ctx *FmtCtx) {
ctx.WriteString("COMMENT ON EXTENSION ")
ctx.FormatNode(&n.Name)
ctx.WriteString(" IS ")
if n.Comment != nil {
lex.EncodeSQLStringWithFlags(&ctx.Buffer, *n.Comment, ctx.flags.EncodeFlags())
} else {
ctx.WriteString("NULL")
}
}

// CommentOnIndex represents a COMMENT ON INDEX statement.
type CommentOnIndex struct {
Index TableIndexName
Comment *string
}

// Format implements the NodeFormatter interface.
func (n *CommentOnIndex) Format(ctx *FmtCtx) {
ctx.WriteString("COMMENT ON INDEX ")
ctx.FormatNode(&n.Index)
ctx.WriteString(" IS ")
if n.Comment != nil {
lex.EncodeSQLStringWithFlags(&ctx.Buffer, *n.Comment, ctx.flags.EncodeFlags())
} else {
ctx.WriteString("NULL")
}
}

// CommentOnTable represents an COMMENT ON TABLE statement.
type CommentOnTable struct {
Table *UnresolvedObjectName
Comment *string
}

// Format implements the NodeFormatter interface.
func (n *CommentOnTable) Format(ctx *FmtCtx) {
ctx.WriteString("COMMENT ON TABLE ")
ctx.FormatNode(n.Table)
ctx.WriteString(" IS ")
if n.Comment != nil {
lex.EncodeSQLStringWithFlags(&ctx.Buffer, *n.Comment, ctx.flags.EncodeFlags())
} else {
ctx.WriteString("NULL")
}
}
45 changes: 0 additions & 45 deletions postgres/parser/sem/tree/comment_on_column.go

This file was deleted.

45 changes: 0 additions & 45 deletions postgres/parser/sem/tree/comment_on_database.go

This file was deleted.

45 changes: 0 additions & 45 deletions postgres/parser/sem/tree/comment_on_index.go

This file was deleted.

45 changes: 0 additions & 45 deletions postgres/parser/sem/tree/comment_on_table.go

This file was deleted.

Loading