View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.shardingsphere.sql.parser.postgresql.visitor.statement.type;
19  
20  import org.apache.shardingsphere.sql.parser.api.ASTNode;
21  import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DDLStatementVisitor;
22  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AbsoluteCountContext;
23  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AddColumnSpecificationContext;
24  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AddConstraintSpecificationContext;
25  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AllContext;
26  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterAggregateContext;
27  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterCollationContext;
28  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterConversionContext;
29  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterDefaultPrivilegesContext;
30  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterDefinitionClauseContext;
31  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterDomainContext;
32  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterExtensionContext;
33  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterForeignDataWrapperContext;
34  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterForeignTableContext;
35  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterFunctionContext;
36  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterGroupContext;
37  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterIndexContext;
38  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterLanguageContext;
39  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterMaterializedViewContext;
40  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterOperatorContext;
41  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterPolicyContext;
42  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterProcedureContext;
43  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterPublicationContext;
44  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterRenameViewContext;
45  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterRoutineContext;
46  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterRuleContext;
47  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterSchemaContext;
48  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterSequenceContext;
49  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterServerContext;
50  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterStatisticsContext;
51  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterSubscriptionContext;
52  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTableActionContext;
53  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTableContext;
54  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTablespaceContext;
55  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTextSearchConfigurationContext;
56  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTextSearchDictionaryContext;
57  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTextSearchParserContext;
58  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTextSearchTemplateContext;
59  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTriggerContext;
60  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTypeContext;
61  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterViewContext;
62  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.BackwardAllContext;
63  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.BackwardContext;
64  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.BackwardCountContext;
65  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CloseContext;
66  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.ClusterContext;
67  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.ColumnConstraintContext;
68  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.ColumnDefinitionContext;
69  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CommentContext;
70  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CountContext;
71  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateAccessMethodContext;
72  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateAggregateContext;
73  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateCastContext;
74  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateCollationContext;
75  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateConversionContext;
76  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateDatabaseContext;
77  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateDefinitionClauseContext;
78  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateDefinitionContext;
79  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateDomainContext;
80  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateEventTriggerContext;
81  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateExtensionContext;
82  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateForeignDataWrapperContext;
83  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateForeignTableContext;
84  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateFunctionContext;
85  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateIndexContext;
86  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateLanguageContext;
87  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateMaterializedViewContext;
88  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateOperatorContext;
89  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreatePolicyContext;
90  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateProcedureContext;
91  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreatePublicationContext;
92  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateRuleContext;
93  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateSchemaContext;
94  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateSequenceContext;
95  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateTableContext;
96  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateTablespaceContext;
97  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateTextSearchContext;
98  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateTypeContext;
99  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateViewContext;
100 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CursorNameContext;
101 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DeallocateContext;
102 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DeclareContext;
103 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DiscardContext;
104 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropAccessMethodContext;
105 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropAggregateContext;
106 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropCastContext;
107 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropCollationContext;
108 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropColumnSpecificationContext;
109 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropConstraintSpecificationContext;
110 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropConversionContext;
111 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropDatabaseContext;
112 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropDomainContext;
113 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropEventTriggerContext;
114 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropExtensionContext;
115 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropForeignDataWrapperContext;
116 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropForeignTableContext;
117 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropFunctionContext;
118 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropGroupContext;
119 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropIndexContext;
120 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropLanguageContext;
121 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropMaterializedViewContext;
122 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropOperatorClassContext;
123 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropOperatorContext;
124 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropOperatorFamilyContext;
125 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropOwnedContext;
126 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropPolicyContext;
127 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropProcedureContext;
128 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropPublicationContext;
129 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropRoutineContext;
130 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropRuleContext;
131 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropSchemaContext;
132 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropSequenceContext;
133 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropServerContext;
134 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropStatisticsContext;
135 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropSubscriptionContext;
136 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropTableContext;
137 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropTablespaceContext;
138 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropTextSearchContext;
139 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropTriggerContext;
140 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropTypeContext;
141 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropViewContext;
142 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.FetchContext;
143 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.FirstContext;
144 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.ForwardAllContext;
145 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.ForwardContext;
146 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.ForwardCountContext;
147 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.FuncArgExprContext;
148 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.FunctionExprWindowlessContext;
149 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.IndexElemContext;
150 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.IndexNameContext;
151 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.IndexNamesContext;
152 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.IndexParamsContext;
153 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.LastContext;
154 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.ListenContext;
155 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.ModifyColumnSpecificationContext;
156 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.ModifyConstraintSpecificationContext;
157 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.MoveContext;
158 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.NameContext;
159 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.NameListContext;
160 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.NextContext;
161 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.NotifyStmtContext;
162 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.PrepareContext;
163 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.PriorContext;
164 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.RefreshMatViewStmtContext;
165 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.ReindexContext;
166 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.RelativeCountContext;
167 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.RenameColumnSpecificationContext;
168 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.RenameTableSpecificationContext;
169 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.SecurityLabelStmtContext;
170 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.TableConstraintContext;
171 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.TableConstraintUsingIndexContext;
172 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.TableNameClauseContext;
173 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.TableNamesClauseContext;
174 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.TruncateTableContext;
175 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.UnlistenContext;
176 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.ValidateConstraintSpecificationContext;
177 import org.apache.shardingsphere.sql.parser.postgresql.visitor.statement.PostgreSQLStatementVisitor;
178 import org.apache.shardingsphere.sql.parser.sql.common.enums.DirectionType;
179 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.AlterDefinitionSegment;
180 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.CreateDefinitionSegment;
181 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.ColumnDefinitionSegment;
182 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.alter.AddColumnDefinitionSegment;
183 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.alter.DropColumnDefinitionSegment;
184 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.alter.ModifyColumnDefinitionSegment;
185 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.alter.RenameColumnSegment;
186 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.ConstraintDefinitionSegment;
187 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.ConstraintSegment;
188 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.AddConstraintDefinitionSegment;
189 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.DropConstraintDefinitionSegment;
190 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.ModifyConstraintDefinitionSegment;
191 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.ValidateConstraintDefinitionSegment;
192 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.cursor.CursorNameSegment;
193 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.cursor.DirectionSegment;
194 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexNameSegment;
195 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
196 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.table.RenameTableDefinitionSegment;
197 import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
198 import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
199 import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.FunctionSegment;
200 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DataTypeSegment;
201 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.NameSegment;
202 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment;
203 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
204 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
205 import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DeleteStatement;
206 import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.InsertStatement;
207 import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
208 import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.UpdateStatement;
209 import org.apache.shardingsphere.sql.parser.sql.common.value.collection.CollectionValue;
210 import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
211 import org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.NumberLiteralValue;
212 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterAggregateStatement;
213 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterCollationStatement;
214 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterConversionStatement;
215 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterDefaultPrivilegesStatement;
216 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterDomainStatement;
217 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterExtensionStatement;
218 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterForeignDataWrapperStatement;
219 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterForeignTableStatement;
220 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterFunctionStatement;
221 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterGroupStatement;
222 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterIndexStatement;
223 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterLanguageStatement;
224 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterMaterializedViewStatement;
225 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterOperatorStatement;
226 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterPolicyStatement;
227 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterProcedureStatement;
228 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterPublicationStatement;
229 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterRoutineStatement;
230 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterRuleStatement;
231 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterSchemaStatement;
232 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterSequenceStatement;
233 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterServerStatement;
234 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterStatisticsStatement;
235 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterSubscriptionStatement;
236 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterTableStatement;
237 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterTablespaceStatement;
238 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterTextSearchStatement;
239 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterTriggerStatement;
240 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterTypeStatement;
241 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterViewStatement;
242 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCloseStatement;
243 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLClusterStatement;
244 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCommentStatement;
245 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateAccessMethodStatement;
246 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateAggregateStatement;
247 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateCastStatement;
248 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateCollationStatement;
249 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateConversionStatement;
250 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateDatabaseStatement;
251 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateDomainStatement;
252 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateEventTriggerStatement;
253 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateExtensionStatement;
254 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateForeignDataWrapperStatement;
255 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateForeignTableStatement;
256 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateFunctionStatement;
257 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateIndexStatement;
258 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateLanguageStatement;
259 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateMaterializedViewStatement;
260 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateOperatorStatement;
261 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreatePolicyStatement;
262 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateProcedureStatement;
263 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreatePublicationStatement;
264 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateRuleStatement;
265 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateSchemaStatement;
266 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateSequenceStatement;
267 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateTableStatement;
268 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateTablespaceStatement;
269 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateTextSearchStatement;
270 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateTypeStatement;
271 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateViewStatement;
272 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDeallocateStatement;
273 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDeclareStatement;
274 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDiscardStatement;
275 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropAccessMethodStatement;
276 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropAggregateStatement;
277 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropCastStatement;
278 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropCollationStatement;
279 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropConversionStatement;
280 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropDatabaseStatement;
281 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropDomainStatement;
282 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropEventTriggerStatement;
283 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropExtensionStatement;
284 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropForeignDataWrapperStatement;
285 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropForeignTableStatement;
286 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropFunctionStatement;
287 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropGroupStatement;
288 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropIndexStatement;
289 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropLanguageStatement;
290 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropMaterializedViewStatement;
291 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropOperatorClassStatement;
292 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropOperatorFamilyStatement;
293 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropOperatorStatement;
294 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropOwnedStatement;
295 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropPolicyStatement;
296 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropProcedureStatement;
297 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropPublicationStatement;
298 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropRoutineStatement;
299 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropRuleStatement;
300 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropSchemaStatement;
301 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropSequenceStatement;
302 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropServerStatement;
303 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropStatisticsStatement;
304 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropSubscriptionStatement;
305 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropTableStatement;
306 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropTablespaceStatement;
307 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropTextSearchStatement;
308 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropTriggerStatement;
309 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropTypeStatement;
310 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropViewStatement;
311 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLFetchStatement;
312 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLListenStatement;
313 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLMoveStatement;
314 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLNotifyStmtStatement;
315 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLPrepareStatement;
316 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLRefreshMatViewStmtStatement;
317 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLReindexStatement;
318 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLSecurityLabelStmtStatement;
319 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLTruncateStatement;
320 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLUnlistenStatement;
321 
322 import java.util.ArrayList;
323 import java.util.Collection;
324 import java.util.Collections;
325 import java.util.Iterator;
326 import java.util.LinkedList;
327 import java.util.Optional;
328 import java.util.stream.Collectors;
329 
330 /**
331  * DDL statement visitor for PostgreSQL.
332  */
333 public final class PostgreSQLDDLStatementVisitor extends PostgreSQLStatementVisitor implements DDLStatementVisitor {
334     
335     @SuppressWarnings("unchecked")
336     @Override
337     public ASTNode visitCreateTable(final CreateTableContext ctx) {
338         PostgreSQLCreateTableStatement result = new PostgreSQLCreateTableStatement(null != ctx.ifNotExists());
339         result.setTable((SimpleTableSegment) visit(ctx.tableName()));
340         if (null != ctx.createDefinitionClause()) {
341             CollectionValue<CreateDefinitionSegment> createDefinitions = (CollectionValue<CreateDefinitionSegment>) visit(ctx.createDefinitionClause());
342             for (CreateDefinitionSegment each : createDefinitions.getValue()) {
343                 if (each instanceof ColumnDefinitionSegment) {
344                     result.getColumnDefinitions().add((ColumnDefinitionSegment) each);
345                 } else if (each instanceof ConstraintDefinitionSegment) {
346                     result.getConstraintDefinitions().add((ConstraintDefinitionSegment) each);
347                 }
348             }
349         }
350         return result;
351     }
352     
353     @Override
354     public ASTNode visitCreateDefinitionClause(final CreateDefinitionClauseContext ctx) {
355         CollectionValue<CreateDefinitionSegment> result = new CollectionValue<>();
356         for (CreateDefinitionContext each : ctx.createDefinition()) {
357             if (null != each.columnDefinition()) {
358                 result.getValue().add((ColumnDefinitionSegment) visit(each.columnDefinition()));
359             }
360             if (null != each.tableConstraint()) {
361                 result.getValue().add((ConstraintDefinitionSegment) visit(each.tableConstraint()));
362             }
363         }
364         return result;
365     }
366     
367     @SuppressWarnings("unchecked")
368     @Override
369     public ASTNode visitAlterTable(final AlterTableContext ctx) {
370         PostgreSQLAlterTableStatement result = new PostgreSQLAlterTableStatement();
371         result.setTable((SimpleTableSegment) visit(ctx.tableNameClause().tableName()));
372         if (null != ctx.alterDefinitionClause()) {
373             for (AlterDefinitionSegment each : ((CollectionValue<AlterDefinitionSegment>) visit(ctx.alterDefinitionClause())).getValue()) {
374                 if (each instanceof AddColumnDefinitionSegment) {
375                     result.getAddColumnDefinitions().add((AddColumnDefinitionSegment) each);
376                 } else if (each instanceof ModifyColumnDefinitionSegment) {
377                     result.getModifyColumnDefinitions().add((ModifyColumnDefinitionSegment) each);
378                 } else if (each instanceof DropColumnDefinitionSegment) {
379                     result.getDropColumnDefinitions().add((DropColumnDefinitionSegment) each);
380                 } else if (each instanceof AddConstraintDefinitionSegment) {
381                     result.getAddConstraintDefinitions().add((AddConstraintDefinitionSegment) each);
382                 } else if (each instanceof ValidateConstraintDefinitionSegment) {
383                     result.getValidateConstraintDefinitions().add((ValidateConstraintDefinitionSegment) each);
384                 } else if (each instanceof ModifyConstraintDefinitionSegment) {
385                     result.getModifyConstraintDefinitions().add((ModifyConstraintDefinitionSegment) each);
386                 } else if (each instanceof DropConstraintDefinitionSegment) {
387                     result.getDropConstraintDefinitions().add((DropConstraintDefinitionSegment) each);
388                 } else if (each instanceof RenameTableDefinitionSegment) {
389                     result.setRenameTable(((RenameTableDefinitionSegment) each).getRenameTable());
390                 } else if (each instanceof RenameColumnSegment) {
391                     result.getRenameColumnDefinitions().add((RenameColumnSegment) each);
392                 }
393             }
394         }
395         return result;
396     }
397     
398     @Override
399     public ASTNode visitAlterAggregate(final AlterAggregateContext ctx) {
400         return new PostgreSQLAlterAggregateStatement();
401     }
402     
403     @Override
404     public ASTNode visitAlterCollation(final AlterCollationContext ctx) {
405         return new PostgreSQLAlterCollationStatement();
406     }
407     
408     @Override
409     public ASTNode visitAlterDefaultPrivileges(final AlterDefaultPrivilegesContext ctx) {
410         return new PostgreSQLAlterDefaultPrivilegesStatement();
411     }
412     
413     @Override
414     public ASTNode visitAlterForeignDataWrapper(final AlterForeignDataWrapperContext ctx) {
415         return new PostgreSQLAlterForeignDataWrapperStatement();
416     }
417     
418     @Override
419     public ASTNode visitAlterDefinitionClause(final AlterDefinitionClauseContext ctx) {
420         CollectionValue<AlterDefinitionSegment> result = new CollectionValue<>();
421         if (null != ctx.alterTableActions()) {
422             result.getValue().addAll(ctx.alterTableActions().alterTableAction().stream().flatMap(each -> getAlterDefinitionSegments(each).stream()).collect(Collectors.toList()));
423         }
424         if (null != ctx.renameColumnSpecification()) {
425             result.getValue().add((RenameColumnSegment) visit(ctx.renameColumnSpecification()));
426         }
427         if (null != ctx.renameTableSpecification()) {
428             result.getValue().add((RenameTableDefinitionSegment) visit(ctx.renameTableSpecification()));
429         }
430         return result;
431     }
432     
433     @SuppressWarnings("unchecked")
434     private Collection<AlterDefinitionSegment> getAlterDefinitionSegments(final AlterTableActionContext ctx) {
435         Collection<AlterDefinitionSegment> result = new LinkedList<>();
436         if (null != ctx.addColumnSpecification()) {
437             result.addAll(((CollectionValue<AddColumnDefinitionSegment>) visit(ctx.addColumnSpecification())).getValue());
438         }
439         if (null != ctx.addConstraintSpecification() && null != ctx.addConstraintSpecification().tableConstraint()) {
440             result.add((AddConstraintDefinitionSegment) visit(ctx.addConstraintSpecification()));
441         }
442         if (null != ctx.validateConstraintSpecification()) {
443             result.add((ValidateConstraintDefinitionSegment) visit(ctx.validateConstraintSpecification()));
444         }
445         if (null != ctx.modifyColumnSpecification()) {
446             result.add((ModifyColumnDefinitionSegment) visit(ctx.modifyColumnSpecification()));
447         }
448         if (null != ctx.modifyConstraintSpecification()) {
449             result.add((ModifyConstraintDefinitionSegment) visit(ctx.modifyConstraintSpecification()));
450         }
451         if (null != ctx.dropColumnSpecification()) {
452             result.add((DropColumnDefinitionSegment) visit(ctx.dropColumnSpecification()));
453         }
454         if (null != ctx.dropConstraintSpecification()) {
455             result.add((DropConstraintDefinitionSegment) visit(ctx.dropConstraintSpecification()));
456         }
457         return result;
458     }
459     
460     @Override
461     public ASTNode visitAlterForeignTable(final AlterForeignTableContext ctx) {
462         return new PostgreSQLAlterForeignTableStatement();
463     }
464     
465     @Override
466     public ASTNode visitDropForeignTable(final DropForeignTableContext ctx) {
467         return new PostgreSQLDropForeignTableStatement();
468     }
469     
470     @Override
471     public ASTNode visitAlterGroup(final AlterGroupContext ctx) {
472         return new PostgreSQLAlterGroupStatement();
473     }
474     
475     @Override
476     public ASTNode visitAlterMaterializedView(final AlterMaterializedViewContext ctx) {
477         return new PostgreSQLAlterMaterializedViewStatement();
478     }
479     
480     @Override
481     public ASTNode visitAlterOperator(final AlterOperatorContext ctx) {
482         return new PostgreSQLAlterOperatorStatement();
483     }
484     
485     @Override
486     public ASTNode visitAddConstraintSpecification(final AddConstraintSpecificationContext ctx) {
487         return new AddConstraintDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (ConstraintDefinitionSegment) visit(ctx.tableConstraint()));
488     }
489     
490     @Override
491     public ASTNode visitValidateConstraintSpecification(final ValidateConstraintSpecificationContext ctx) {
492         return new ValidateConstraintDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (ConstraintSegment) visit(ctx.constraintName()));
493     }
494     
495     @Override
496     public ASTNode visitModifyConstraintSpecification(final ModifyConstraintSpecificationContext ctx) {
497         return new ModifyConstraintDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (ConstraintSegment) visit(ctx.constraintName()));
498     }
499     
500     @Override
501     public ASTNode visitDropConstraintSpecification(final DropConstraintSpecificationContext ctx) {
502         return new DropConstraintDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (ConstraintSegment) visit(ctx.constraintName()));
503     }
504     
505     @Override
506     public ASTNode visitAlterDomain(final AlterDomainContext ctx) {
507         return new PostgreSQLAlterDomainStatement();
508     }
509     
510     @Override
511     public ASTNode visitAlterPolicy(final AlterPolicyContext ctx) {
512         return new PostgreSQLAlterPolicyStatement();
513     }
514     
515     @Override
516     public ASTNode visitAlterPublication(final AlterPublicationContext ctx) {
517         return new PostgreSQLAlterPublicationStatement();
518     }
519     
520     @Override
521     public ASTNode visitAlterSubscription(final AlterSubscriptionContext ctx) {
522         return new PostgreSQLAlterSubscriptionStatement();
523     }
524     
525     @Override
526     public ASTNode visitAlterTrigger(final AlterTriggerContext ctx) {
527         return new PostgreSQLAlterTriggerStatement();
528     }
529     
530     @Override
531     public ASTNode visitAlterType(final AlterTypeContext ctx) {
532         return new PostgreSQLAlterTypeStatement();
533     }
534     
535     @Override
536     public ASTNode visitRenameTableSpecification(final RenameTableSpecificationContext ctx) {
537         RenameTableDefinitionSegment result = new RenameTableDefinitionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
538         TableNameSegment tableName = new TableNameSegment(ctx.identifier().start.getStartIndex(), ctx.identifier().stop.getStopIndex(), (IdentifierValue) visit(ctx.identifier()));
539         result.setRenameTable(new SimpleTableSegment(tableName));
540         return result;
541     }
542     
543     @Override
544     public ASTNode visitAddColumnSpecification(final AddColumnSpecificationContext ctx) {
545         CollectionValue<AddColumnDefinitionSegment> result = new CollectionValue<>();
546         ColumnDefinitionContext columnDefinition = ctx.columnDefinition();
547         if (null != columnDefinition) {
548             AddColumnDefinitionSegment addColumnDefinition = new AddColumnDefinitionSegment(
549                     ctx.columnDefinition().getStart().getStartIndex(), columnDefinition.getStop().getStopIndex(), Collections.singleton((ColumnDefinitionSegment) visit(columnDefinition)));
550             result.getValue().add(addColumnDefinition);
551         }
552         return result;
553     }
554     
555     @Override
556     public ASTNode visitColumnDefinition(final ColumnDefinitionContext ctx) {
557         ColumnSegment column = (ColumnSegment) visit(ctx.columnName());
558         DataTypeSegment dataType = (DataTypeSegment) visit(ctx.dataType());
559         boolean isPrimaryKey = ctx.columnConstraint().stream().anyMatch(each -> null != each.columnConstraintOption() && null != each.columnConstraintOption().primaryKey());
560         // TODO parse not null
561         ColumnDefinitionSegment result = new ColumnDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), column, dataType, isPrimaryKey, false);
562         for (ColumnConstraintContext each : ctx.columnConstraint()) {
563             if (null != each.columnConstraintOption().tableName()) {
564                 result.getReferencedTables().add((SimpleTableSegment) visit(each.columnConstraintOption().tableName()));
565             }
566         }
567         return result;
568     }
569     
570     @Override
571     public ASTNode visitTableConstraintUsingIndex(final TableConstraintUsingIndexContext ctx) {
572         ConstraintDefinitionSegment result = new ConstraintDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex());
573         if (null != ctx.constraintName()) {
574             result.setConstraintName((ConstraintSegment) visit(ctx.constraintName()));
575         }
576         if (null != ctx.indexName()) {
577             result.setIndexName((IndexSegment) visit(ctx.indexName()));
578         }
579         return result;
580     }
581     
582     @SuppressWarnings("unchecked")
583     @Override
584     public ASTNode visitTableConstraint(final TableConstraintContext ctx) {
585         ConstraintDefinitionSegment result = new ConstraintDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex());
586         if (null != ctx.constraintClause()) {
587             result.setConstraintName((ConstraintSegment) visit(ctx.constraintClause().constraintName()));
588         }
589         if (null != ctx.tableConstraintOption().primaryKey()) {
590             result.getPrimaryKeyColumns().addAll(((CollectionValue<ColumnSegment>) visit(ctx.tableConstraintOption().columnNames(0))).getValue());
591         }
592         if (null != ctx.tableConstraintOption().FOREIGN()) {
593             result.setReferencedTable((SimpleTableSegment) visit(ctx.tableConstraintOption().tableName()));
594         }
595         return result;
596     }
597     
598     @Override
599     public ASTNode visitModifyColumnSpecification(final ModifyColumnSpecificationContext ctx) {
600         // TODO visit pk and table ref
601         ColumnSegment column = (ColumnSegment) visit(ctx.modifyColumn().columnName());
602         DataTypeSegment dataType = null == ctx.dataType() ? null : (DataTypeSegment) visit(ctx.dataType());
603         ColumnDefinitionSegment columnDefinition = new ColumnDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), column, dataType, false, false);
604         return new ModifyColumnDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), columnDefinition);
605     }
606     
607     @Override
608     public ASTNode visitDropColumnSpecification(final DropColumnSpecificationContext ctx) {
609         return new DropColumnDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), Collections.singleton((ColumnSegment) visit(ctx.columnName())));
610     }
611     
612     @Override
613     public ASTNode visitRenameColumnSpecification(final RenameColumnSpecificationContext ctx) {
614         return new RenameColumnSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (ColumnSegment) visit(ctx.columnName(0)), (ColumnSegment) visit(ctx.columnName(1)));
615     }
616     
617     @SuppressWarnings("unchecked")
618     @Override
619     public ASTNode visitDropTable(final DropTableContext ctx) {
620         boolean containsCascade = null != ctx.dropTableOpt() && null != ctx.dropTableOpt().CASCADE();
621         PostgreSQLDropTableStatement result = new PostgreSQLDropTableStatement(null != ctx.ifExists(), containsCascade);
622         result.getTables().addAll(((CollectionValue<SimpleTableSegment>) visit(ctx.tableNames())).getValue());
623         return result;
624     }
625     
626     @SuppressWarnings("unchecked")
627     @Override
628     public ASTNode visitTruncateTable(final TruncateTableContext ctx) {
629         PostgreSQLTruncateStatement result = new PostgreSQLTruncateStatement();
630         result.getTables().addAll(((CollectionValue<SimpleTableSegment>) visit(ctx.tableNamesClause())).getValue());
631         return result;
632     }
633     
634     @Override
635     public ASTNode visitDropPolicy(final DropPolicyContext ctx) {
636         return new PostgreSQLDropPolicyStatement();
637     }
638     
639     @Override
640     public ASTNode visitDropRule(final DropRuleContext ctx) {
641         return new PostgreSQLDropRuleStatement();
642     }
643     
644     @Override
645     public ASTNode visitDropStatistics(final DropStatisticsContext ctx) {
646         return new PostgreSQLDropStatisticsStatement();
647     }
648     
649     @Override
650     public ASTNode visitDropPublication(final DropPublicationContext ctx) {
651         return new PostgreSQLDropPublicationStatement();
652     }
653     
654     @Override
655     public ASTNode visitDropSubscription(final DropSubscriptionContext ctx) {
656         return new PostgreSQLDropSubscriptionStatement();
657     }
658     
659     @SuppressWarnings("unchecked")
660     @Override
661     public ASTNode visitCreateIndex(final CreateIndexContext ctx) {
662         PostgreSQLCreateIndexStatement result = new PostgreSQLCreateIndexStatement(null != ctx.ifNotExists());
663         result.setTable((SimpleTableSegment) visit(ctx.tableName()));
664         result.getColumns().addAll(((CollectionValue<ColumnSegment>) visit(ctx.indexParams())).getValue());
665         if (null != ctx.indexName()) {
666             result.setIndex((IndexSegment) visit(ctx.indexName()));
667         } else {
668             result.setGeneratedIndexStartIndex(ctx.ON().getSymbol().getStartIndex() - 1);
669         }
670         return result;
671     }
672     
673     @Override
674     public ASTNode visitIndexParams(final IndexParamsContext ctx) {
675         CollectionValue<ColumnSegment> result = new CollectionValue<>();
676         for (IndexElemContext each : ctx.indexElem()) {
677             if (null != each.colId()) {
678                 result.getValue().add(new ColumnSegment(each.colId().start.getStartIndex(), each.colId().stop.getStopIndex(), new IdentifierValue(each.colId().getText())));
679             }
680             if (null != each.functionExprWindowless()) {
681                 FunctionSegment functionSegment = (FunctionSegment) visit(each.functionExprWindowless());
682                 functionSegment.getParameters().forEach(param -> {
683                     if (param instanceof ColumnSegment) {
684                         result.getValue().add((ColumnSegment) param);
685                     }
686                 });
687             }
688         }
689         return result;
690     }
691     
692     @Override
693     public ASTNode visitFunctionExprWindowless(final FunctionExprWindowlessContext ctx) {
694         FunctionSegment result = new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.funcApplication().funcName().getText(), getOriginalText(ctx));
695         result.getParameters().addAll(getExpressions(ctx.funcApplication().funcArgList().funcArgExpr()));
696         return result;
697     }
698     
699     private Collection<ExpressionSegment> getExpressions(final Collection<FuncArgExprContext> aExprContexts) {
700         if (null == aExprContexts) {
701             return Collections.emptyList();
702         }
703         Collection<ExpressionSegment> result = new ArrayList<>(aExprContexts.size());
704         for (FuncArgExprContext each : aExprContexts) {
705             result.add((ExpressionSegment) visit(each.aExpr()));
706         }
707         return result;
708     }
709     
710     @Override
711     public ASTNode visitAlterIndex(final AlterIndexContext ctx) {
712         PostgreSQLAlterIndexStatement result = new PostgreSQLAlterIndexStatement();
713         result.setIndex(createIndexSegment((SimpleTableSegment) visit(ctx.qualifiedName())));
714         if (null != ctx.alterIndexDefinitionClause().renameIndexSpecification()) {
715             result.setRenameIndex((IndexSegment) visit(ctx.alterIndexDefinitionClause().renameIndexSpecification().indexName()));
716         }
717         return result;
718     }
719     
720     private IndexSegment createIndexSegment(final SimpleTableSegment tableSegment) {
721         IndexNameSegment indexName = new IndexNameSegment(tableSegment.getTableName().getStartIndex(), tableSegment.getTableName().getStopIndex(), tableSegment.getTableName().getIdentifier());
722         IndexSegment result = new IndexSegment(tableSegment.getStartIndex(), tableSegment.getStopIndex(), indexName);
723         tableSegment.getOwner().ifPresent(result::setOwner);
724         return result;
725     }
726     
727     @SuppressWarnings("unchecked")
728     @Override
729     public ASTNode visitDropIndex(final DropIndexContext ctx) {
730         PostgreSQLDropIndexStatement result = new PostgreSQLDropIndexStatement(null != ctx.ifExists());
731         result.getIndexes().addAll(createIndexSegments(((CollectionValue<SimpleTableSegment>) visit(ctx.qualifiedNameList())).getValue()));
732         return result;
733     }
734     
735     private Collection<IndexSegment> createIndexSegments(final Collection<SimpleTableSegment> tableSegments) {
736         Collection<IndexSegment> result = new LinkedList<>();
737         for (SimpleTableSegment each : tableSegments) {
738             result.add(createIndexSegment(each));
739         }
740         return result;
741     }
742     
743     @Override
744     public ASTNode visitIndexNames(final IndexNamesContext ctx) {
745         CollectionValue<IndexSegment> result = new CollectionValue<>();
746         for (IndexNameContext each : ctx.indexName()) {
747             result.getValue().add((IndexSegment) visit(each));
748         }
749         return result;
750     }
751     
752     @Override
753     public ASTNode visitTableNameClause(final TableNameClauseContext ctx) {
754         return visit(ctx.tableName());
755     }
756     
757     @Override
758     public ASTNode visitTableNamesClause(final TableNamesClauseContext ctx) {
759         Collection<SimpleTableSegment> tableSegments = new LinkedList<>();
760         for (int i = 0; i < ctx.tableNameClause().size(); i++) {
761             tableSegments.add((SimpleTableSegment) visit(ctx.tableNameClause(i)));
762         }
763         CollectionValue<SimpleTableSegment> result = new CollectionValue<>();
764         result.getValue().addAll(tableSegments);
765         return result;
766     }
767     
768     @Override
769     public ASTNode visitAlterFunction(final AlterFunctionContext ctx) {
770         return new PostgreSQLAlterFunctionStatement();
771     }
772     
773     @Override
774     public ASTNode visitAlterProcedure(final AlterProcedureContext ctx) {
775         return new PostgreSQLAlterProcedureStatement();
776     }
777     
778     @Override
779     public ASTNode visitCreateFunction(final CreateFunctionContext ctx) {
780         return new PostgreSQLCreateFunctionStatement();
781     }
782     
783     @Override
784     public ASTNode visitCreateProcedure(final CreateProcedureContext ctx) {
785         return new PostgreSQLCreateProcedureStatement();
786     }
787     
788     @Override
789     public ASTNode visitDropFunction(final DropFunctionContext ctx) {
790         return new PostgreSQLDropFunctionStatement();
791     }
792     
793     @Override
794     public ASTNode visitDropGroup(final DropGroupContext ctx) {
795         return new PostgreSQLDropGroupStatement();
796     }
797     
798     @SuppressWarnings("unchecked")
799     @Override
800     public ASTNode visitDropView(final DropViewContext ctx) {
801         PostgreSQLDropViewStatement result = new PostgreSQLDropViewStatement();
802         result.getViews().addAll(((CollectionValue<SimpleTableSegment>) visit(ctx.qualifiedNameList())).getValue());
803         return result;
804     }
805     
806     @Override
807     public ASTNode visitCreateView(final CreateViewContext ctx) {
808         PostgreSQLCreateViewStatement result = new PostgreSQLCreateViewStatement();
809         result.setView((SimpleTableSegment) visit(ctx.qualifiedName()));
810         result.setViewDefinition(getOriginalText(ctx.select()));
811         result.setSelect((SelectStatement) visit(ctx.select()));
812         return result;
813     }
814     
815     @Override
816     public ASTNode visitAlterView(final AlterViewContext ctx) {
817         PostgreSQLAlterViewStatement result = new PostgreSQLAlterViewStatement();
818         result.setView((SimpleTableSegment) visit(ctx.qualifiedName()));
819         if (ctx.alterViewClauses() instanceof AlterRenameViewContext) {
820             NameContext nameContext = ((AlterRenameViewContext) ctx.alterViewClauses()).name();
821             result.setRenameView(new SimpleTableSegment(new TableNameSegment(nameContext.getStart().getStartIndex(),
822                     nameContext.getStop().getStopIndex(), (IdentifierValue) visit(nameContext.identifier()))));
823         }
824         return result;
825     }
826     
827     @Override
828     public ASTNode visitDropDatabase(final DropDatabaseContext ctx) {
829         PostgreSQLDropDatabaseStatement result = new PostgreSQLDropDatabaseStatement();
830         result.setDatabaseName(((IdentifierValue) visit(ctx.name())).getValue());
831         result.setIfExists(null != ctx.ifExists());
832         return result;
833     }
834     
835     @Override
836     public ASTNode visitAlterRoutine(final AlterRoutineContext ctx) {
837         return new PostgreSQLAlterRoutineStatement();
838     }
839     
840     @Override
841     public ASTNode visitAlterRule(final AlterRuleContext ctx) {
842         return new PostgreSQLAlterRuleStatement();
843     }
844     
845     @Override
846     public ASTNode visitDropProcedure(final DropProcedureContext ctx) {
847         return new PostgreSQLDropProcedureStatement();
848     }
849     
850     @Override
851     public ASTNode visitDropRoutine(final DropRoutineContext ctx) {
852         return new PostgreSQLDropRoutineStatement();
853     }
854     
855     @Override
856     public ASTNode visitCreateDatabase(final CreateDatabaseContext ctx) {
857         PostgreSQLCreateDatabaseStatement result = new PostgreSQLCreateDatabaseStatement();
858         result.setDatabaseName(((IdentifierValue) visit(ctx.name())).getValue());
859         return result;
860     }
861     
862     @Override
863     public ASTNode visitCreateSequence(final CreateSequenceContext ctx) {
864         PostgreSQLCreateSequenceStatement result = new PostgreSQLCreateSequenceStatement();
865         result.setSequenceName(((SimpleTableSegment) visit(ctx.qualifiedName())).getTableName().getIdentifier().getValue());
866         return result;
867     }
868     
869     @Override
870     public ASTNode visitAlterSequence(final AlterSequenceContext ctx) {
871         PostgreSQLAlterSequenceStatement result = new PostgreSQLAlterSequenceStatement();
872         result.setSequenceName(((SimpleTableSegment) visit(ctx.qualifiedName())).getTableName().getIdentifier().getValue());
873         return result;
874     }
875     
876     @SuppressWarnings({"unchecked", "rawtypes"})
877     @Override
878     public ASTNode visitDropSequence(final DropSequenceContext ctx) {
879         PostgreSQLDropSequenceStatement result = new PostgreSQLDropSequenceStatement();
880         result.setSequenceNames(((CollectionValue) visit(ctx.qualifiedNameList())).getValue());
881         return result;
882     }
883     
884     @Override
885     public ASTNode visitPrepare(final PrepareContext ctx) {
886         PostgreSQLPrepareStatement result = new PostgreSQLPrepareStatement();
887         if (null != ctx.preparableStmt().select()) {
888             result.setSelect((SelectStatement) visit(ctx.preparableStmt().select()));
889         }
890         if (null != ctx.preparableStmt().insert()) {
891             result.setInsert((InsertStatement) visit(ctx.preparableStmt().insert()));
892         }
893         if (null != ctx.preparableStmt().update()) {
894             result.setUpdate((UpdateStatement) visit(ctx.preparableStmt().update()));
895         }
896         if (null != ctx.preparableStmt().delete()) {
897             result.setDelete((DeleteStatement) visit(ctx.preparableStmt().delete()));
898         }
899         return result;
900     }
901     
902     @Override
903     public ASTNode visitDeallocate(final DeallocateContext ctx) {
904         return new PostgreSQLDeallocateStatement();
905     }
906     
907     @Override
908     public ASTNode visitDropCast(final DropCastContext ctx) {
909         return new PostgreSQLDropCastStatement();
910     }
911     
912     @Override
913     public ASTNode visitCreateTablespace(final CreateTablespaceContext ctx) {
914         return new PostgreSQLCreateTablespaceStatement();
915     }
916     
917     @Override
918     public ASTNode visitAlterTablespace(final AlterTablespaceContext ctx) {
919         return new PostgreSQLAlterTablespaceStatement();
920     }
921     
922     @Override
923     public ASTNode visitDropTablespace(final DropTablespaceContext ctx) {
924         return new PostgreSQLDropTablespaceStatement();
925     }
926     
927     @Override
928     public ASTNode visitDropTextSearch(final DropTextSearchContext ctx) {
929         return new PostgreSQLDropTextSearchStatement();
930     }
931     
932     @Override
933     public ASTNode visitDropDomain(final DropDomainContext ctx) {
934         return new PostgreSQLDropDomainStatement();
935     }
936     
937     @Override
938     public ASTNode visitCreateDomain(final CreateDomainContext ctx) {
939         return new PostgreSQLCreateDomainStatement();
940     }
941     
942     @Override
943     public ASTNode visitCreateRule(final CreateRuleContext ctx) {
944         return new PostgreSQLCreateRuleStatement();
945     }
946     
947     @Override
948     public ASTNode visitCreateLanguage(final CreateLanguageContext ctx) {
949         return new PostgreSQLCreateLanguageStatement();
950     }
951     
952     @Override
953     public ASTNode visitCreateSchema(final CreateSchemaContext ctx) {
954         PostgreSQLCreateSchemaStatement result = new PostgreSQLCreateSchemaStatement();
955         if (null != ctx.createSchemaClauses().colId()) {
956             result.setSchemaName(new IdentifierValue(ctx.createSchemaClauses().colId().getText()));
957         }
958         if (null != ctx.createSchemaClauses().roleSpec() && null != ctx.createSchemaClauses().roleSpec().identifier()) {
959             result.setUsername((IdentifierValue) visit(ctx.createSchemaClauses().roleSpec().identifier()));
960         }
961         return result;
962     }
963     
964     @Override
965     public ASTNode visitAlterSchema(final AlterSchemaContext ctx) {
966         PostgreSQLAlterSchemaStatement result = new PostgreSQLAlterSchemaStatement();
967         result.setSchemaName((IdentifierValue) visit(ctx.name().get(0)));
968         if (ctx.name().size() > 1) {
969             result.setRenameSchema((IdentifierValue) visit(ctx.name().get(1)));
970         }
971         return result;
972     }
973     
974     @SuppressWarnings("unchecked")
975     @Override
976     public ASTNode visitDropSchema(final DropSchemaContext ctx) {
977         PostgreSQLDropSchemaStatement result = new PostgreSQLDropSchemaStatement();
978         result.getSchemaNames().addAll(((CollectionValue<IdentifierValue>) visit(ctx.nameList())).getValue());
979         result.setContainsCascade(null != ctx.dropBehavior() && null != ctx.dropBehavior().CASCADE());
980         return result;
981     }
982     
983     @SuppressWarnings("unchecked")
984     @Override
985     public ASTNode visitNameList(final NameListContext ctx) {
986         CollectionValue<IdentifierValue> result = new CollectionValue<>();
987         if (null != ctx.nameList()) {
988             result.combine((CollectionValue<IdentifierValue>) visit(ctx.nameList()));
989         }
990         if (null != ctx.name()) {
991             result.getValue().add((IdentifierValue) visit(ctx.name()));
992         }
993         return result;
994     }
995     
996     @Override
997     public ASTNode visitAlterLanguage(final AlterLanguageContext ctx) {
998         return new PostgreSQLAlterLanguageStatement();
999     }
1000     
1001     @Override
1002     public ASTNode visitAlterServer(final AlterServerContext ctx) {
1003         return new PostgreSQLAlterServerStatement();
1004     }
1005     
1006     @Override
1007     public ASTNode visitAlterStatistics(final AlterStatisticsContext ctx) {
1008         return new PostgreSQLAlterStatisticsStatement();
1009     }
1010     
1011     @Override
1012     public ASTNode visitDropLanguage(final DropLanguageContext ctx) {
1013         return new PostgreSQLDropLanguageStatement();
1014     }
1015     
1016     @Override
1017     public ASTNode visitCreateConversion(final CreateConversionContext ctx) {
1018         return new PostgreSQLCreateConversionStatement();
1019     }
1020     
1021     @Override
1022     public ASTNode visitCreateType(final CreateTypeContext ctx) {
1023         return new PostgreSQLCreateTypeStatement();
1024     }
1025     
1026     @Override
1027     public ASTNode visitDropConversion(final DropConversionContext ctx) {
1028         return new PostgreSQLDropConversionStatement();
1029     }
1030     
1031     @Override
1032     public ASTNode visitAlterConversion(final AlterConversionContext ctx) {
1033         return new PostgreSQLAlterConversionStatement();
1034     }
1035     
1036     @Override
1037     public ASTNode visitCreateTextSearch(final CreateTextSearchContext ctx) {
1038         return new PostgreSQLCreateTextSearchStatement();
1039     }
1040     
1041     @Override
1042     public ASTNode visitAlterTextSearchConfiguration(final AlterTextSearchConfigurationContext ctx) {
1043         return new PostgreSQLAlterTextSearchStatement();
1044     }
1045     
1046     @Override
1047     public ASTNode visitAlterTextSearchDictionary(final AlterTextSearchDictionaryContext ctx) {
1048         return new PostgreSQLAlterTextSearchStatement();
1049     }
1050     
1051     @Override
1052     public ASTNode visitAlterTextSearchTemplate(final AlterTextSearchTemplateContext ctx) {
1053         return new PostgreSQLAlterTextSearchStatement();
1054     }
1055     
1056     @Override
1057     public ASTNode visitAlterTextSearchParser(final AlterTextSearchParserContext ctx) {
1058         return new PostgreSQLAlterTextSearchStatement();
1059     }
1060     
1061     @Override
1062     public ASTNode visitCreateExtension(final CreateExtensionContext ctx) {
1063         return new PostgreSQLCreateExtensionStatement();
1064     }
1065     
1066     @Override
1067     public ASTNode visitAlterExtension(final AlterExtensionContext ctx) {
1068         return new PostgreSQLAlterExtensionStatement();
1069     }
1070     
1071     @Override
1072     public ASTNode visitDropExtension(final DropExtensionContext ctx) {
1073         return new PostgreSQLDropExtensionStatement();
1074     }
1075     
1076     @Override
1077     public ASTNode visitDiscard(final DiscardContext ctx) {
1078         return new PostgreSQLDiscardStatement();
1079     }
1080     
1081     @Override
1082     public ASTNode visitDropOwned(final DropOwnedContext ctx) {
1083         return new PostgreSQLDropOwnedStatement();
1084     }
1085     
1086     @Override
1087     public ASTNode visitDropOperator(final DropOperatorContext ctx) {
1088         return new PostgreSQLDropOperatorStatement();
1089     }
1090     
1091     @Override
1092     public ASTNode visitDropMaterializedView(final DropMaterializedViewContext ctx) {
1093         return new PostgreSQLDropMaterializedViewStatement();
1094     }
1095     
1096     @Override
1097     public ASTNode visitDropEventTrigger(final DropEventTriggerContext ctx) {
1098         return new PostgreSQLDropEventTriggerStatement();
1099     }
1100     
1101     @Override
1102     public ASTNode visitDropAggregate(final DropAggregateContext ctx) {
1103         return new PostgreSQLDropAggregateStatement();
1104     }
1105     
1106     @Override
1107     public ASTNode visitDropCollation(final DropCollationContext ctx) {
1108         return new PostgreSQLDropCollationStatement();
1109     }
1110     
1111     @Override
1112     public ASTNode visitDropForeignDataWrapper(final DropForeignDataWrapperContext ctx) {
1113         return new PostgreSQLDropForeignDataWrapperStatement();
1114     }
1115     
1116     @Override
1117     public ASTNode visitDropTrigger(final DropTriggerContext ctx) {
1118         return new PostgreSQLDropTriggerStatement();
1119     }
1120     
1121     @Override
1122     public ASTNode visitDropType(final DropTypeContext ctx) {
1123         return new PostgreSQLDropTypeStatement();
1124     }
1125     
1126     @Override
1127     public ASTNode visitComment(final CommentContext ctx) {
1128         if (null != ctx.commentClauses().objectTypeAnyName() && null != ctx.commentClauses().objectTypeAnyName().TABLE()) {
1129             return commentOnTable(ctx);
1130         }
1131         if (null != ctx.commentClauses().COLUMN()) {
1132             return commentOnColumn(ctx);
1133         }
1134         if (null != ctx.commentClauses().objectTypeNameOnAnyName()) {
1135             return getTableFromComment(ctx);
1136         }
1137         return new PostgreSQLCommentStatement();
1138     }
1139     
1140     @SuppressWarnings("unchecked")
1141     private PostgreSQLCommentStatement commentOnColumn(final CommentContext ctx) {
1142         PostgreSQLCommentStatement result = new PostgreSQLCommentStatement();
1143         Iterator<NameSegment> nameSegmentIterator = ((CollectionValue<NameSegment>) visit(ctx.commentClauses().anyName())).getValue().iterator();
1144         Optional<NameSegment> columnName = nameSegmentIterator.hasNext() ? Optional.of(nameSegmentIterator.next()) : Optional.empty();
1145         columnName.ifPresent(optional -> result.setColumn(new ColumnSegment(optional.getStartIndex(), optional.getStopIndex(), optional.getIdentifier())));
1146         result.setComment(new IdentifierValue(ctx.commentClauses().commentText().getText()));
1147         setTableSegment(result, nameSegmentIterator);
1148         return result;
1149     }
1150     
1151     @SuppressWarnings("unchecked")
1152     private PostgreSQLCommentStatement commentOnTable(final CommentContext ctx) {
1153         PostgreSQLCommentStatement result = new PostgreSQLCommentStatement();
1154         Iterator<NameSegment> nameSegmentIterator = ((CollectionValue<NameSegment>) visit(ctx.commentClauses().anyName())).getValue().iterator();
1155         result.setComment(new IdentifierValue(ctx.commentClauses().commentText().getText()));
1156         setTableSegment(result, nameSegmentIterator);
1157         return result;
1158     }
1159     
1160     private void setTableSegment(final PostgreSQLCommentStatement statement, final Iterator<NameSegment> nameSegmentIterator) {
1161         Optional<NameSegment> tableName = nameSegmentIterator.hasNext() ? Optional.of(nameSegmentIterator.next()) : Optional.empty();
1162         tableName.ifPresent(optional -> statement.setTable(new SimpleTableSegment(new TableNameSegment(optional.getStartIndex(), optional.getStopIndex(), optional.getIdentifier()))));
1163         Optional<NameSegment> schemaName = nameSegmentIterator.hasNext() ? Optional.of(nameSegmentIterator.next()) : Optional.empty();
1164         schemaName.ifPresent(optional -> statement.getTable().setOwner(new OwnerSegment(optional.getStartIndex(), optional.getStopIndex(), optional.getIdentifier())));
1165         Optional<NameSegment> databaseName = nameSegmentIterator.hasNext() ? Optional.of(nameSegmentIterator.next()) : Optional.empty();
1166         databaseName.ifPresent(optional -> statement.getTable().getOwner()
1167                 .ifPresent(owner -> owner.setOwner(new OwnerSegment(optional.getStartIndex(), optional.getStopIndex(), optional.getIdentifier()))));
1168     }
1169     
1170     private PostgreSQLCommentStatement getTableFromComment(final CommentContext ctx) {
1171         PostgreSQLCommentStatement result = new PostgreSQLCommentStatement();
1172         result.setTable((SimpleTableSegment) visit(ctx.commentClauses().tableName()));
1173         return result;
1174     }
1175     
1176     @Override
1177     public ASTNode visitDropOperatorClass(final DropOperatorClassContext ctx) {
1178         return new PostgreSQLDropOperatorClassStatement();
1179     }
1180     
1181     @Override
1182     public ASTNode visitDropOperatorFamily(final DropOperatorFamilyContext ctx) {
1183         return new PostgreSQLDropOperatorFamilyStatement();
1184     }
1185     
1186     @Override
1187     public ASTNode visitDropAccessMethod(final DropAccessMethodContext ctx) {
1188         return new PostgreSQLDropAccessMethodStatement();
1189     }
1190     
1191     @Override
1192     public ASTNode visitDropServer(final DropServerContext ctx) {
1193         return new PostgreSQLDropServerStatement();
1194     }
1195     
1196     @Override
1197     public ASTNode visitDeclare(final DeclareContext ctx) {
1198         PostgreSQLDeclareStatement result = new PostgreSQLDeclareStatement();
1199         result.setCursorName((CursorNameSegment) visit(ctx.cursorName()));
1200         result.setSelect((SelectStatement) visit(ctx.select()));
1201         return result;
1202     }
1203     
1204     @Override
1205     public ASTNode visitFetch(final FetchContext ctx) {
1206         PostgreSQLFetchStatement result = new PostgreSQLFetchStatement();
1207         result.setCursorName((CursorNameSegment) visit(ctx.cursorName()));
1208         if (null != ctx.direction()) {
1209             result.setDirection((DirectionSegment) visit(ctx.direction()));
1210         }
1211         return result;
1212     }
1213     
1214     @Override
1215     public ASTNode visitMove(final MoveContext ctx) {
1216         PostgreSQLMoveStatement result = new PostgreSQLMoveStatement();
1217         result.setCursorName((CursorNameSegment) visit(ctx.cursorName()));
1218         if (null != ctx.direction()) {
1219             result.setDirection((DirectionSegment) visit(ctx.direction()));
1220         }
1221         return result;
1222     }
1223     
1224     @Override
1225     public ASTNode visitClose(final CloseContext ctx) {
1226         PostgreSQLCloseStatement result = new PostgreSQLCloseStatement();
1227         if (null != ctx.cursorName()) {
1228             result.setCursorName((CursorNameSegment) visit(ctx.cursorName()));
1229         }
1230         result.setCloseAll(null != ctx.ALL());
1231         return result;
1232     }
1233     
1234     @Override
1235     public ASTNode visitCursorName(final CursorNameContext ctx) {
1236         return new CursorNameSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), (IdentifierValue) visit(ctx.name()));
1237     }
1238     
1239     @Override
1240     public ASTNode visitCluster(final ClusterContext ctx) {
1241         PostgreSQLClusterStatement result = new PostgreSQLClusterStatement();
1242         if (null != ctx.tableName()) {
1243             result.setTable((SimpleTableSegment) visit(ctx.tableName()));
1244         }
1245         if (null != ctx.clusterIndexSpecification()) {
1246             result.setIndex((IndexSegment) visit(ctx.clusterIndexSpecification().indexName()));
1247         }
1248         return result;
1249     }
1250     
1251     @Override
1252     public ASTNode visitCreateAccessMethod(final CreateAccessMethodContext ctx) {
1253         return new PostgreSQLCreateAccessMethodStatement();
1254     }
1255     
1256     @Override
1257     public ASTNode visitCreateAggregate(final CreateAggregateContext ctx) {
1258         return new PostgreSQLCreateAggregateStatement();
1259     }
1260     
1261     @Override
1262     public ASTNode visitNext(final NextContext ctx) {
1263         DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1264         result.setDirectionType(DirectionType.NEXT);
1265         return result;
1266     }
1267     
1268     @Override
1269     public ASTNode visitPrior(final PriorContext ctx) {
1270         DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1271         result.setDirectionType(DirectionType.PRIOR);
1272         return result;
1273     }
1274     
1275     @Override
1276     public ASTNode visitFirst(final FirstContext ctx) {
1277         DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1278         result.setDirectionType(DirectionType.FIRST);
1279         return result;
1280     }
1281     
1282     @Override
1283     public ASTNode visitLast(final LastContext ctx) {
1284         DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1285         result.setDirectionType(DirectionType.LAST);
1286         return result;
1287     }
1288     
1289     @Override
1290     public ASTNode visitAbsoluteCount(final AbsoluteCountContext ctx) {
1291         DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1292         result.setDirectionType(DirectionType.ABSOLUTE_COUNT);
1293         result.setCount(((NumberLiteralValue) visit(ctx.signedIconst())).getValue().longValue());
1294         return result;
1295     }
1296     
1297     @Override
1298     public ASTNode visitRelativeCount(final RelativeCountContext ctx) {
1299         DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1300         result.setDirectionType(DirectionType.RELATIVE_COUNT);
1301         result.setCount(((NumberLiteralValue) visit(ctx.signedIconst())).getValue().longValue());
1302         return result;
1303     }
1304     
1305     @Override
1306     public ASTNode visitCount(final CountContext ctx) {
1307         DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1308         result.setDirectionType(DirectionType.COUNT);
1309         result.setCount(((NumberLiteralValue) visit(ctx.signedIconst())).getValue().longValue());
1310         return result;
1311     }
1312     
1313     @Override
1314     public ASTNode visitAll(final AllContext ctx) {
1315         DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1316         result.setDirectionType(DirectionType.ALL);
1317         return result;
1318     }
1319     
1320     @Override
1321     public ASTNode visitForward(final ForwardContext ctx) {
1322         DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1323         result.setDirectionType(DirectionType.FORWARD);
1324         return result;
1325     }
1326     
1327     @Override
1328     public ASTNode visitForwardCount(final ForwardCountContext ctx) {
1329         DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1330         result.setDirectionType(DirectionType.FORWARD_COUNT);
1331         result.setCount(((NumberLiteralValue) visit(ctx.signedIconst())).getValue().longValue());
1332         return result;
1333     }
1334     
1335     @Override
1336     public ASTNode visitForwardAll(final ForwardAllContext ctx) {
1337         DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1338         result.setDirectionType(DirectionType.FORWARD_ALL);
1339         return result;
1340     }
1341     
1342     @Override
1343     public ASTNode visitBackward(final BackwardContext ctx) {
1344         DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1345         result.setDirectionType(DirectionType.BACKWARD);
1346         return result;
1347     }
1348     
1349     @Override
1350     public ASTNode visitBackwardCount(final BackwardCountContext ctx) {
1351         DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1352         result.setDirectionType(DirectionType.BACKWARD_COUNT);
1353         result.setCount(((NumberLiteralValue) visit(ctx.signedIconst())).getValue().longValue());
1354         return result;
1355     }
1356     
1357     @Override
1358     public ASTNode visitBackwardAll(final BackwardAllContext ctx) {
1359         DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1360         result.setDirectionType(DirectionType.BACKWARD_ALL);
1361         return result;
1362     }
1363     
1364     @Override
1365     public ASTNode visitCreateCast(final CreateCastContext ctx) {
1366         return new PostgreSQLCreateCastStatement();
1367     }
1368     
1369     @Override
1370     public ASTNode visitListen(final ListenContext ctx) {
1371         String channelName = ctx.channelName().getText();
1372         PostgreSQLListenStatement result = new PostgreSQLListenStatement();
1373         result.setChannelName(channelName);
1374         return result;
1375     }
1376     
1377     @Override
1378     public ASTNode visitUnlisten(final UnlistenContext ctx) {
1379         return new PostgreSQLUnlistenStatement();
1380     }
1381     
1382     @Override
1383     public ASTNode visitNotifyStmt(final NotifyStmtContext ctx) {
1384         return new PostgreSQLNotifyStmtStatement();
1385     }
1386     
1387     @Override
1388     public ASTNode visitCreateCollation(final CreateCollationContext ctx) {
1389         return new PostgreSQLCreateCollationStatement();
1390     }
1391     
1392     @Override
1393     public ASTNode visitRefreshMatViewStmt(final RefreshMatViewStmtContext ctx) {
1394         return new PostgreSQLRefreshMatViewStmtStatement();
1395     }
1396     
1397     @Override
1398     public ASTNode visitReindex(final ReindexContext ctx) {
1399         return new PostgreSQLReindexStatement();
1400     }
1401     
1402     @Override
1403     public ASTNode visitSecurityLabelStmt(final SecurityLabelStmtContext ctx) {
1404         return new PostgreSQLSecurityLabelStmtStatement();
1405     }
1406     
1407     @Override
1408     public ASTNode visitCreateEventTrigger(final CreateEventTriggerContext ctx) {
1409         return new PostgreSQLCreateEventTriggerStatement();
1410     }
1411     
1412     @Override
1413     public ASTNode visitCreateForeignDataWrapper(final CreateForeignDataWrapperContext ctx) {
1414         return new PostgreSQLCreateForeignDataWrapperStatement();
1415     }
1416     
1417     @Override
1418     public ASTNode visitCreateForeignTable(final CreateForeignTableContext ctx) {
1419         return new PostgreSQLCreateForeignTableStatement();
1420     }
1421     
1422     @Override
1423     public ASTNode visitCreateMaterializedView(final CreateMaterializedViewContext ctx) {
1424         return new PostgreSQLCreateMaterializedViewStatement();
1425     }
1426     
1427     @Override
1428     public ASTNode visitCreateOperator(final CreateOperatorContext ctx) {
1429         return new PostgreSQLCreateOperatorStatement();
1430     }
1431     
1432     @Override
1433     public ASTNode visitCreatePolicy(final CreatePolicyContext ctx) {
1434         return new PostgreSQLCreatePolicyStatement();
1435     }
1436     
1437     @Override
1438     public ASTNode visitCreatePublication(final CreatePublicationContext ctx) {
1439         return new PostgreSQLCreatePublicationStatement();
1440     }
1441 }