-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support some postgres syntaxes - 1 (#85)
- Loading branch information
1 parent
9b74d0e
commit e90f5d4
Showing
13 changed files
with
1,477 additions
and
1,110 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Copyright 2024 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 2020 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 "strings" | ||
|
||
var _ Statement = &AlterAggregate{} | ||
|
||
// AlterAggregate represents a ALTER AGGREGATE statement. | ||
type AlterAggregate struct { | ||
Name Name | ||
AggSig *AggregateSignature | ||
Rename Name | ||
Owner string | ||
Schema string | ||
} | ||
|
||
// Format implements the NodeFormatter interface. | ||
func (node *AlterAggregate) Format(ctx *FmtCtx) { | ||
ctx.WriteString("ALTER AGGREGATE ") | ||
ctx.FormatNode(&node.Name) | ||
ctx.WriteString(" (") | ||
node.AggSig.Format(ctx) | ||
ctx.WriteString(" )") | ||
|
||
if node.Rename != "" { | ||
ctx.WriteString(" RENAME ") | ||
ctx.FormatNode(&node.Rename) | ||
} else if node.Owner != "" { | ||
ctx.WriteString(" OWNER TO ") | ||
ctx.FormatNameP(&node.Owner) | ||
} else if node.Schema != "" { | ||
ctx.WriteString(" SET SCHEMA ") | ||
ctx.FormatNameP(&node.Schema) | ||
} | ||
} | ||
|
||
// AggregateSignature represents an aggregate_signature clause. | ||
type AggregateSignature struct { | ||
All bool | ||
Arg *AggregateArg | ||
OrderBy *AggregateArg | ||
} | ||
|
||
// Format implements the NodeFormatter interface. | ||
func (node *AggregateSignature) Format(ctx *FmtCtx) { | ||
if node.All { | ||
ctx.WriteString(" * ") | ||
} else { | ||
if node.Arg != nil { | ||
ctx.WriteByte(' ') | ||
node.Arg.Format(ctx) | ||
} | ||
if node.OrderBy != nil { | ||
ctx.WriteString(" ORDER BY ") | ||
node.Arg.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, ", ")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2024 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 2020 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 | ||
|
||
var _ Statement = &AlterCollation{} | ||
|
||
// AlterCollation represents a ALTER COLLATION statement. | ||
type AlterCollation struct { | ||
Name Name | ||
RefreshVersion bool | ||
Rename Name | ||
Owner string | ||
Schema string | ||
} | ||
|
||
// Format implements the NodeFormatter interface. | ||
func (node *AlterCollation) Format(ctx *FmtCtx) { | ||
ctx.WriteString("ALTER COLLATION ") | ||
ctx.FormatNode(&node.Name) | ||
if node.RefreshVersion { | ||
ctx.WriteString(" REFRESH VERSION") | ||
} else if node.Rename != "" { | ||
ctx.WriteString(" RENAME ") | ||
ctx.FormatNode(&node.Rename) | ||
} else if node.Owner != "" { | ||
ctx.WriteString(" OWNER TO ") | ||
ctx.FormatNameP(&node.Owner) | ||
} else if node.Schema != "" { | ||
ctx.WriteString(" SET SCHEMA ") | ||
ctx.FormatNameP(&node.Schema) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2024 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 2020 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 | ||
|
||
var _ Statement = &AlterConversion{} | ||
|
||
// AlterConversion represents a ALTER COLLATION statement. | ||
type AlterConversion struct { | ||
Name Name | ||
RefreshVersion bool | ||
Rename Name | ||
Owner string | ||
Schema string | ||
} | ||
|
||
// Format implements the NodeFormatter interface. | ||
func (node *AlterConversion) Format(ctx *FmtCtx) { | ||
ctx.WriteString("ALTER COLLATION ") | ||
ctx.FormatNode(&node.Name) | ||
if node.RefreshVersion { | ||
ctx.WriteString(" REFRESH VERSION") | ||
} else if node.Rename != "" { | ||
ctx.WriteString(" RENAME ") | ||
ctx.FormatNode(&node.Rename) | ||
} else if node.Owner != "" { | ||
ctx.WriteString(" OWNER TO ") | ||
ctx.FormatNameP(&node.Owner) | ||
} else if node.Schema != "" { | ||
ctx.WriteString(" SET SCHEMA ") | ||
ctx.FormatNameP(&node.Schema) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.