Repository: apache/incubator-shardingsphere (java)

Issue:
Correct the `DataTypeName` for each DataBase
The definition of `DataTypeName` in `RuleName.g4`(Antlr grammer file) of each DataBase is not correct so far, therefore this issue is created to correct them. The sub-task list is below,
- [x] Correct the `DataTypeName` for `MySQL`.
- [x] Correct the `DataTypeName` for `PostgreSQL`. 
- [x] Correct the `DataTypeName` for `SQLServer`. 
- [x] Correct the `DataTypeName` for `Oracle`. 
- [x] Correct the `DataTypeName` for `SQL92`. 

Q1: How to learn about the definition of `DataTypeName`?
A:
 - Official document of each DataBase, i.g [MySQL](https://dev.mysql.com/doc/refman/8.0/en/data-types.html).
- [Antlr SQL grammer](https://github.com/antlr/grammars-v4/tree/master/sql)
- Other related Website. (I am not sure. 😃 )

Q2: Which file of ShardingSphere does `DataTypeName` exist?
A: All files named with `RuleName.g4`

Pull request description:
#4482 Correct the `DataTypeName` for PostgreSQL
Fixes #4482.

Changes proposed in this pull request:
-  add PostgreSQL dataType

Note:
- doublePrecision is support `double precision` . [DATATYPE-FLOAT](http://www.postgres.cn/docs/11/datatype-numeric.html#DATATYPE-FLOAT)
- identifier is support `complex type` [ROWTYPES-DECLARING](http://www.postgres.cn/docs/11/rowtypes.html#ROWTYPES-DECLARING)


Patch:
diff --git a/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/TableTokenGenerator.java b/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/TableTokenGenerator.java
index 339ffcb0ba4..d5b37258215 100644
--- a/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/TableTokenGenerator.java
+++ b/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/TableTokenGenerator.java
@@ -17,31 +17,13 @@
 
 package org.apache.shardingsphere.sharding.rewrite.token.generator.impl;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
 import lombok.Setter;
 import org.apache.shardingsphere.core.rule.ShardingRule;
 import org.apache.shardingsphere.core.rule.aware.ShardingRuleAware;
 import org.apache.shardingsphere.sharding.rewrite.token.pojo.impl.TableToken;
-import org.apache.shardingsphere.sql.parser.relation.segment.table.Table;
-import org.apache.shardingsphere.sql.parser.relation.segment.table.TablesContext;
 import org.apache.shardingsphere.sql.parser.relation.statement.SQLStatementContext;
-import org.apache.shardingsphere.sql.parser.sql.segment.dml.column.ColumnSegment;
-import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ColumnProjectionSegment;
-import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ProjectionSegment;
-import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ProjectionsSegment;
-import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ShorthandProjectionSegment;
-import org.apache.shardingsphere.sql.parser.sql.segment.dml.order.item.ColumnOrderByItemSegment;
-import org.apache.shardingsphere.sql.parser.sql.segment.dml.order.item.OrderByItemSegment;
-import org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.AndPredicate;
-import org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.PredicateSegment;
-import org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.WhereSegment;
-import org.apache.shardingsphere.sql.parser.sql.segment.generic.OwnerAvailable;
-import org.apache.shardingsphere.sql.parser.sql.segment.generic.OwnerSegment;
 import org.apache.shardingsphere.sql.parser.sql.segment.generic.TableSegment;
-import org.apache.shardingsphere.sql.parser.sql.statement.dml.SelectStatement;
 import org.apache.shardingsphere.sql.parser.sql.statement.generic.TableSegmentsAvailable;
-import org.apache.shardingsphere.sql.parser.sql.statement.generic.WhereSegmentAvailable;
 import org.apache.shardingsphere.underlying.rewrite.sql.token.generator.CollectionSQLTokenGenerator;
 
 import java.util.Collection;
@@ -63,128 +45,17 @@ public final class TableTokenGenerator implements CollectionSQLTokenGenerator, S
     
     @Override
     public Collection<TableToken> generateSQLTokens(final SQLStatementContext sqlStatementContext) {
-        if (!(sqlStatementContext.getSqlStatement() instanceof TableSegmentsAvailable)) {
-            return Collections.emptyList();
-        }
-        Collection<TableToken> result = new LinkedList<>();
-        for (TableSegment each : ((TableSegmentsAvailable) sqlStatementContext.getSqlStatement()).getAllTables()) {
-            if (shardingRule.findTableRule(each.getIdentifier().getValue()).isPresent()) {
-                result.add(new TableToken(each.getStartIndex(), each.getStopIndex(), each.getIdentifier()));
-            }
-        }
-        if (sqlStatementContext.getSqlStatement() instanceof WhereSegmentAvailable && ((WhereSegmentAvailable) sqlStatementContext.getSqlStatement()).getWhere().isPresent()) {
-            result.addAll(generateSQLTokens(sqlStatementContext, ((WhereSegmentAvailable) sqlStatementContext.getSqlStatement()).getWhere().get()));
-        }
-        if (sqlStatementContext.getSqlStatement() instanceof SelectStatement) {
-            result.addAll(generateSQLTokens(sqlStatementContext, ((SelectStatement) sqlStatementContext.getSqlStatement()).getProjections()));
-            if (((SelectStatement) sqlStatementContext.getSqlStatement()).getGroupBy().isPresent()) {
-                result.addAll(generateSQLTokens(sqlStatementContext, ((SelectStatement) sqlStatementContext.getSqlStatement()).getGroupBy().get().getGroupByItems()));
-            }
-            if (((SelectStatement) sqlStatementContext.getSqlStatement()).getOrderBy().isPresent()) {
-                result.addAll(generateSQLTokens(sqlStatementContext, ((SelectStatement) sqlStatementContext.getSqlStatement()).getOrderBy().get().getOrderByItems()));
-            }
-        }
-        return result;
-    }
-    
-    private Collection<TableToken> generateSQLTokens(final SQLStatementContext sqlStatementContext, final WhereSegment where) {
-        Collection<TableToken> result = new LinkedList<>();
-        for (AndPredicate each : where.getAndPredicates()) {
-            for (PredicateSegment predicate : each.getPredicates()) {
-                result.addAll(getTableTokens(sqlStatementContext, predicate));
-            }
-        }
-        return result;
-    }
-    
-    private Collection<TableToken> generateSQLTokens(final SQLStatementContext sqlStatementContext, final ProjectionsSegment projectionsSegment) {
-        Collection<TableToken> result = new LinkedList<>();
-        for (ProjectionSegment each : projectionsSegment.getProjections()) {
-            if (each instanceof ShorthandProjectionSegment) {
-                Optional<TableToken> tableToken = generateSQLToken(sqlStatementContext, (ShorthandProjectionSegment) each);
-                if (tableToken.isPresent()) {
-                    result.add(tableToken.get());
-                }
-            }
-            if (each instanceof ColumnProjectionSegment) {
-                Optional<TableToken> tableToken = generateSQLToken(sqlStatementContext, (ColumnProjectionSegment) each);
-                if (tableToken.isPresent()) {
-                    result.add(tableToken.get());
-                }
-            }
-        }
-        return result;
-    }
-    
-    private Collection<TableToken> generateSQLTokens(final SQLStatementContext sqlStatementContext, final Collection<OrderByItemSegment> orderBys) {
-        Collection<TableToken> result = new LinkedList<>();
-        for (OrderByItemSegment each : orderBys) {
-            if (isToGenerateTableToken(sqlStatementContext.getTablesContext(), each)) {
-                Preconditions.checkState(((ColumnOrderByItemSegment) each).getColumn().getOwner().isPresent());
-                OwnerSegment segment = ((ColumnOrderByItemSegment) each).getColumn().getOwner().get();
-                result.add(new TableToken(segment.getStartIndex(), segment.getStopIndex(), segment.getIdentifier()));
-            }
-        }
-        return result;
-    }
-    
-    private Optional<TableToken> generateSQLToken(final SQLStatementContext sqlStatementContext, final OwnerAvailable segment) {
-        Optional<OwnerSegment> owner = segment.getOwner();
-        return owner.isPresent() && isToGenerateTableToken(sqlStatementContext, owner.get())
-                ? Optional.of(new TableToken(owner.get().getStartIndex(), owner.get().getStopIndex(), owner.get().getIdentifier())) : Optional.<TableToken>absent();
+        return sqlStatementContext.getSqlStatement() instanceof TableSegmentsAvailable
+                ? generateSQLTokens((TableSegmentsAvailable) sqlStatementContext.getSqlStatement()) : Collections.<TableToken>emptyList();
     }
     
-    private Collection<TableToken> getTableTokens(final SQLStatementContext sqlStatementContext, final PredicateSegment predicate) {
+    private Collection<TableToken> generateSQLTokens(final TableSegmentsAvailable sqlStatement) {
         Collection<TableToken> result = new LinkedList<>();
-        if (isToGenerateTableTokenLeftValue(sqlStatementContext.getTablesContext(), predicate)) {
-            Preconditions.checkState(predicate.getColumn().getOwner().isPresent());
-            OwnerSegment segment = predicate.getColumn().getOwner().get();
-            if (shardingRule.findTableRule(segment.getIdentifier().getValue()).isPresent()) {
-                result.add(new TableToken(segment.getStartIndex(), segment.getStopIndex(), segment.getIdentifier()));
-            }
-        }
-        if (isToGenerateTableTokenForRightValue(sqlStatementContext.getTablesContext(), predicate)) {
-            Preconditions.checkState(((ColumnSegment) predicate.getRightValue()).getOwner().isPresent());
-            OwnerSegment segment = ((ColumnSegment) predicate.getRightValue()).getOwner().get();
-            if (shardingRule.findTableRule(segment.getIdentifier().getValue()).isPresent()) {
-                result.add(new TableToken(segment.getStartIndex(), segment.getStopIndex(), segment.getIdentifier()));
-            }
-        }
-        if (isToGenerateTableTokenForProjection(sqlStatementContext.getTablesContext(), predicate)) {
-            Preconditions.checkState(((ColumnProjectionSegment) predicate.getRightValue()).getOwner().isPresent());
-            OwnerSegment segment = ((ColumnProjectionSegment) predicate.getRightValue()).getOwner().get();
-            if (shardingRule.findTableRule(segment.getIdentifier().getValue()).isPresent()) {
-                result.add(new TableToken(segment.getStartIndex(), segment.getStopIndex(), segment.getIdentifier()));
+        for (TableSegment each : sqlStatement.getAllTables()) {
+            if (shardingRule.findTableRule(each.getIdentifier().getValue()).isPresent()) {
+                result.add(new TableToken(each.getStartIndex(), each.getStopIndex(), each.getIdentifier()));
             }
         }
         return result;
     }
-    
-    private boolean isToGenerateTableTokenLeftValue(final TablesContext tablesContext, final PredicateSegment predicate) {
-        return predicate.getColumn().getOwner().isPresent() && isTable(predicate.getColumn().getOwner().get(), tablesContext);
-    }
-    
-    private boolean isToGenerateTableTokenForRightValue(final TablesContext tablesContext, final PredicateSegment predicate) {
-        return predicate.getRightValue() instanceof ColumnSegment
-                && ((ColumnSegment) predicate.getRightValue()).getOwner().isPresent() && isTable(((ColumnSegment) predicate.getRightValue()).getOwner().get(), tablesContext);
-    }
-    
-    private boolean isToGenerateTableTokenForProjection(final TablesContext tablesContext, final PredicateSegment predicate) {
-        return predicate.getRightValue() instanceof ColumnProjectionSegment && ((ColumnProjectionSegment) predicate.getRightValue()).getOwner().isPresent()
-                && isTable(((ColumnProjectionSegment) predicate.getRightValue()).getOwner().get(), tablesContext);
-    }
-    
-    private boolean isToGenerateTableToken(final TablesContext tablesContext, final OrderByItemSegment orderByItemSegment) {
-        return orderByItemSegment instanceof ColumnOrderByItemSegment && ((ColumnOrderByItemSegment) orderByItemSegment).getColumn().getOwner().isPresent() 
-                && isTable(((ColumnOrderByItemSegment) orderByItemSegment).getColumn().getOwner().get(), tablesContext);
-    }
-    
-    private boolean isToGenerateTableToken(final SQLStatementContext sqlStatementContext, final OwnerSegment ownerSegment) {
-        Optional<Table> table = sqlStatementContext.getTablesContext().find(ownerSegment.getIdentifier().getValue());
-        return table.isPresent() && !table.get().getAlias().isPresent();
-    }
-    
-    private boolean isTable(final OwnerSegment owner, final TablesContext tablesContext) {
-        return !tablesContext.findTableFromAlias(owner.getIdentifier().getValue()).isPresent();
-    }
 }
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/predicate/PredicateExtractor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/predicate/PredicateExtractor.java
new file mode 100644
index 00000000000..4d9753aea95
--- /dev/null
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/predicate/PredicateExtractor.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.shardingsphere.sql.parser.sql.predicate;
+
+import com.google.common.base.Preconditions;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.sql.parser.sql.segment.dml.column.ColumnSegment;
+import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ColumnProjectionSegment;
+import org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.PredicateSegment;
+import org.apache.shardingsphere.sql.parser.sql.segment.generic.OwnerSegment;
+import org.apache.shardingsphere.sql.parser.sql.segment.generic.TableSegment;
+
+import java.util.Collection;
+import java.util.LinkedList;
+
+/**
+ * Predicate extractor.
+ */
+@RequiredArgsConstructor
+public final class PredicateExtractor {
+    
+    private final Collection<TableSegment> tables;
+    
+    private final PredicateSegment predicate;
+    
+    /**
+     * Extract tables.
+     * 
+     * @return table segments
+     */
+    public Collection<TableSegment> extractTables() {
+        Collection<TableSegment> result = new LinkedList<>();
+        if (isToGenerateTableTokenLeftValue()) {
+            Preconditions.checkState(predicate.getColumn().getOwner().isPresent());
+            OwnerSegment segment = predicate.getColumn().getOwner().get();
+            result.add(new TableSegment(segment.getStartIndex(), segment.getStopIndex(), segment.getIdentifier()));
+        }
+        if (isToGenerateTableTokenForRightValue()) {
+            Preconditions.checkState(((ColumnSegment) predicate.getRightValue()).getOwner().isPresent());
+            OwnerSegment segment = ((ColumnSegment) predicate.getRightValue()).getOwner().get();
+            result.add(new TableSegment(segment.getStartIndex(), segment.getStopIndex(), segment.getIdentifier()));
+        }
+        if (isToGenerateTableTokenForProjection()) {
+            Preconditions.checkState(((ColumnProjectionSegment) predicate.getRightValue()).getOwner().isPresent());
+            OwnerSegment segment = ((ColumnProjectionSegment) predicate.getRightValue()).getOwner().get();
+            new TableSegment(segment.getStartIndex(), segment.getStopIndex(), segment.getIdentifier());
+        }
+        return result;
+    }
+    
+    private boolean isToGenerateTableTokenLeftValue() {
+        return predicate.getColumn().getOwner().isPresent() && isTable(predicate.getColumn().getOwner().get());
+    }
+    
+    private boolean isToGenerateTableTokenForRightValue() {
+        return predicate.getRightValue() instanceof ColumnSegment
+                && ((ColumnSegment) predicate.getRightValue()).getOwner().isPresent() && isTable(((ColumnSegment) predicate.getRightValue()).getOwner().get());
+    }
+    
+    private boolean isToGenerateTableTokenForProjection() {
+        return predicate.getRightValue() instanceof ColumnProjectionSegment && ((ColumnProjectionSegment) predicate.getRightValue()).getOwner().isPresent()
+                && isTable(((ColumnProjectionSegment) predicate.getRightValue()).getOwner().get());
+    }
+    
+    private boolean isTable(final OwnerSegment owner) {
+        for (TableSegment each : tables) {
+            if (owner.getIdentifier().getValue().equals(each.getAlias().orNull())) {
+                return false;
+            }
+        }
+        return true;
+    }
+}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/statement/dml/SelectStatement.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/statement/dml/SelectStatement.java
index 2f77a2e9838..d02e7b274e0 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/statement/dml/SelectStatement.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/statement/dml/SelectStatement.java
@@ -18,14 +18,23 @@
 package org.apache.shardingsphere.sql.parser.sql.statement.dml;
 
 import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
 import lombok.Getter;
 import lombok.Setter;
+import org.apache.shardingsphere.sql.parser.sql.predicate.PredicateExtractor;
+import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ProjectionSegment;
 import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ProjectionsSegment;
 import org.apache.shardingsphere.sql.parser.sql.segment.dml.order.GroupBySegment;
 import org.apache.shardingsphere.sql.parser.sql.segment.dml.order.OrderBySegment;
+import org.apache.shardingsphere.sql.parser.sql.segment.dml.order.item.ColumnOrderByItemSegment;
+import org.apache.shardingsphere.sql.parser.sql.segment.dml.order.item.OrderByItemSegment;
 import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.limit.LimitSegment;
+import org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.AndPredicate;
 import org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.LockSegment;
+import org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.PredicateSegment;
 import org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.WhereSegment;
+import org.apache.shardingsphere.sql.parser.sql.segment.generic.OwnerAvailable;
+import org.apache.shardingsphere.sql.parser.sql.segment.generic.OwnerSegment;
 import org.apache.shardingsphere.sql.parser.sql.segment.generic.TableSegment;
 import org.apache.shardingsphere.sql.parser.sql.statement.generic.TableSegmentsAvailable;
 import org.apache.shardingsphere.sql.parser.sql.statement.generic.WhereSegmentAvailable;
@@ -56,16 +65,6 @@ public final class SelectStatement extends DMLStatement implements TableSegments
     
     private LockSegment lock;
     
-    @Override
-    public Collection<TableSegment> getAllTables() {
-        return tables;
-    }
-    
-    @Override
-    public Optional<WhereSegment> getWhere() {
-        return Optional.fromNullable(where);
-    }
-    
     /**
      * Get group by segment.
      * 
@@ -101,4 +100,72 @@ public final class SelectStatement extends DMLStatement implements TableSegments
     public Optional<LockSegment> getLock() {
         return Optional.fromNullable(lock);
     }
+    
+    @Override
+    public Optional<WhereSegment> getWhere() {
+        return Optional.fromNullable(where);
+    }
+    
+    @Override
+    public Collection<TableSegment> getAllTables() {
+        Collection<TableSegment> result = new LinkedList<>(tables);
+        if (null != where) {
+            result.addAll(getAllTablesFromWhere());
+        }
+        result.addAll(getAllTablesFromProjections());
+        if (null != groupBy) {
+            result.addAll(getAllTablesFromOrderByItems(groupBy.getGroupByItems()));
+        }
+        if (null != orderBy) {
+            result.addAll(getAllTablesFromOrderByItems(orderBy.getOrderByItems()));
+        }
+        return result;
+    }
+    
+    private Collection<TableSegment> getAllTablesFromWhere() {
+        Collection<TableSegment> result = new LinkedList<>();
+        for (AndPredicate each : where.getAndPredicates()) {
+            for (PredicateSegment predicate : each.getPredicates()) {
+                result.addAll(new PredicateExtractor(tables, predicate).extractTables());
+            }
+        }
+        return result;
+    }
+    
+    private Collection<TableSegment> getAllTablesFromProjections() {
+        Collection<TableSegment> result = new LinkedList<>();
+        for (ProjectionSegment each : projections.getProjections()) {
+            if (each instanceof OwnerAvailable) {
+                Optional<OwnerSegment> owner = ((OwnerAvailable) each).getOwner();
+                if (owner.isPresent() && isTable(owner.get())) {
+                    result.add(new TableSegment(owner.get().getStartIndex(), owner.get().getStopIndex(), owner.get().getIdentifier()));
+                }
+            }
+        }
+        return result;
+    }
+    
+    private Collection<TableSegment> getAllTablesFromOrderByItems(final Collection<OrderByItemSegment> orderByItems) {
+        Collection<TableSegment> result = new LinkedList<>();
+        for (OrderByItemSegment each : orderByItems) {
+            if (each instanceof ColumnOrderByItemSegment) {
+                Optional<OwnerSegment> owner = ((ColumnOrderByItemSegment) each).getColumn().getOwner();
+                if (owner.isPresent() && isTable(owner.get())) {
+                    Preconditions.checkState(((ColumnOrderByItemSegment) each).getColumn().getOwner().isPresent());
+                    OwnerSegment segment = ((ColumnOrderByItemSegment) each).getColumn().getOwner().get();
+                    result.add(new TableSegment(segment.getStartIndex(), segment.getStopIndex(), segment.getIdentifier()));
+                }
+            }
+        }
+        return result;
+    }
+    
+    private boolean isTable(final OwnerSegment owner) {
+        for (TableSegment each : tables) {
+            if (owner.getIdentifier().getValue().equals(each.getAlias().orNull())) {
+                return false;
+            }
+        }
+        return true;
+    }
 }
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/BaseRule.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/BaseRule.g4
index ae9acbdba94..9b192166c9b 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/BaseRule.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/BaseRule.g4
@@ -303,7 +303,10 @@ dataType
     ;
 
 dataTypeName
-    : identifier
+    : INT | SMALLINT | INTEGER | BIGINT | DECIMAL | NUMERIC | REAL | FLOAT | DOUBLE_PRECISION | SMALLSERIAL | SERIAL | BIGSERIAL
+    | MONEY | VARCHAR | CHARACTER | CHAR | TEXT | NAME | BYTEA | TIMESTAMP | DATE | TIME | INTERVAL | BOOLEAN | ENUM | POINT
+    | LINE | LSEG | BOX | PATH | POLYGON | CIRCLE | CIDR | INET | MACADDR | BIT | VARBIT | TSVECTOR | TSQUERY | UUID | XML
+    | JSON | INTRANGE | NUMRANGE | TSRANGE | TSTZRANGE | DATERANGE | ARRAY | identifier
     ;
 
 dataTypeLength
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/Keyword.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/Keyword.g4
index 6019c6fa0b6..d2e8dbea020 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/Keyword.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/Keyword.g4
@@ -535,3 +535,19 @@ DECIMAL
 TYPE
     : T Y P E
     ;
+
+SMALLINT
+    : S M A L L I N T
+    ;
+
+BIGINT
+    : B I G I N T
+    ;
+
+NUMERIC
+    : N U M E R I C
+    ;
+
+TEXT
+    : T E X T
+    ;
\ No newline at end of file
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/PostgreSQLKeyword.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/PostgreSQLKeyword.g4
index b004d8e78b8..e4dd822397b 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/PostgreSQLKeyword.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/PostgreSQLKeyword.g4
@@ -470,3 +470,131 @@ GROUPS
 RECURSIVE
     : R E C U R S I V E
     ;
+
+INT
+    : I N T [248]?
+    ;
+
+FLOAT
+    : F L O A T [48]?
+    ;
+
+SMALLSERIAL
+    : S M A L L S E R I A L
+    ;
+
+SERIAL
+    : S E R I A L
+    ;
+
+BIGSERIAL
+    : B I G S E R I A L
+    ;
+
+MONEY
+    : M O N E Y
+    ;
+
+VARCHAR
+    : V A R C H A R
+    ;
+
+BYTEA
+    : B Y T E A
+    ;
+
+ENUM
+    : E N U M
+    ;
+
+POINT
+    : P O I N T
+    ;
+
+LINE
+    : L I N E
+    ;
+
+LSEG
+    : L S E G
+    ;
+
+BOX
+    : B O X
+    ;
+
+PATH
+    : P A T H
+    ;
+
+POLYGON
+    : P O L Y G O N
+    ;
+
+CIRCLE
+    : C I R C L E
+    ;
+
+CIDR
+    : C I D R
+    ;
+
+INET
+    : I N E T
+    ;
+
+MACADDR
+    : M A C A D D R [8]?
+    ;
+
+BIT
+    : B I T
+    ;
+
+VARBIT
+    : V A R B I T
+    ;
+
+TSVECTOR
+    : T S V E C T O R
+    ;
+
+TSQUERY
+    : T S Q U E R Y
+    ;
+
+UUID
+    : U U I D
+    ;
+
+XML
+    : X M L
+    ;
+
+JSON
+    : J S O N
+    ;
+
+INTRANGE
+    : I N T [48] R A N G E
+    ;
+
+NUMRANGE
+    : N U M R A N G E
+    ;
+
+TSRANGE
+    : T S R A N G E
+    ;
+
+TSTZRANGE
+    : T S T Z R A N G E
+    ;
+
+DATERANGE
+    : D A T E R A N G E
+    ;
+
+DOUBLE_PRECISION
+    : D O U B L E [ ]+ P R E C I S I O N
+    ;
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/visitor/PostgreSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/visitor/PostgreSQLVisitor.java
index d905d6596f1..ff324c94a18 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/visitor/PostgreSQLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/visitor/PostgreSQLVisitor.java
@@ -460,6 +460,10 @@ public abstract class PostgreSQLVisitor extends PostgreSQLStatementBaseVisitor<A
     
     @Override
     public final ASTNode visitDataTypeName(final DataTypeNameContext ctx) {
+        IdentifierContext identifierContext = ctx.identifier();
+        if (null != identifierContext) {
+            return new KeywordValue(identifierContext.getText());
+        }
         return new KeywordValue(ctx.getText());
     }
     
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-relation/src/main/java/org/apache/shardingsphere/sql/parser/relation/segment/table/TablesContext.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-relation/src/main/java/org/apache/shardingsphere/sql/parser/relation/segment/table/TablesContext.java
index 8b40568172e..aed533d3d42 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-relation/src/main/java/org/apache/shardingsphere/sql/parser/relation/segment/table/TablesContext.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-relation/src/main/java/org/apache/shardingsphere/sql/parser/relation/segment/table/TablesContext.java
@@ -24,6 +24,9 @@ import org.apache.shardingsphere.sql.parser.relation.metadata.RelationMetas;
 import org.apache.shardingsphere.sql.parser.sql.segment.dml.column.ColumnSegment;
 import org.apache.shardingsphere.sql.parser.sql.segment.generic.TableSegment;
 import org.apache.shardingsphere.sql.parser.sql.statement.SQLStatement;
+import org.apache.shardingsphere.sql.parser.sql.statement.dml.DeleteStatement;
+import org.apache.shardingsphere.sql.parser.sql.statement.dml.SelectStatement;
+import org.apache.shardingsphere.sql.parser.sql.statement.dml.UpdateStatement;
 import org.apache.shardingsphere.sql.parser.sql.statement.generic.TableSegmentsAvailable;
 
 import java.util.ArrayList;
@@ -48,7 +51,7 @@ public final class TablesContext {
             tables = Collections.emptyList();
             return;
         }
-        Collection<TableSegment> tableSegments = ((TableSegmentsAvailable) sqlStatement).getAllTables();
+        Collection<TableSegment> tableSegments = getAllTables((TableSegmentsAvailable) sqlStatement);
         tables = new ArrayList<>(tableSegments.size());
         Collection<String> aliases = getAlias(tableSegments);
         for (TableSegment each : tableSegments) {
@@ -61,6 +64,19 @@ public final class TablesContext {
         }
     }
     
+    private Collection<TableSegment> getAllTables(final TableSegmentsAvailable sqlStatement) {
+        if (sqlStatement instanceof SelectStatement) {
+            return ((SelectStatement) sqlStatement).getTables();
+        }
+        if (sqlStatement instanceof UpdateStatement) {
+            return ((UpdateStatement) sqlStatement).getTables();
+        }
+        if (sqlStatement instanceof DeleteStatement) {
+            return ((DeleteStatement) sqlStatement).getTables();
+        }
+        return sqlStatement.getAllTables();
+    }
+    
     private Collection<String> getAlias(final Collection<TableSegment> tableSegments) {
         Collection<String> result = new HashSet<>(tableSegments.size(), 1);
         for (TableSegment each : tableSegments) {


Test patch:
diff --git a/sharding-core/sharding-core-rewrite/src/test/resources/sharding/select.xml b/sharding-core/sharding-core-rewrite/src/test/resources/sharding/select.xml
index a21538d80f2..bcf46f7051a 100644
--- a/sharding-core/sharding-core-rewrite/src/test/resources/sharding/select.xml
+++ b/sharding-core/sharding-core-rewrite/src/test/resources/sharding/select.xml
@@ -322,4 +322,9 @@
         <input sql="SELECT t_account.account_id, t_account.password, t_account.amount AS a, status AS s FROM t_account WHERE t_account.account_id = 1 AND t_account.password = 'aaa' AND t_account.amount = 1000 AND t_account.status = 'OK'" />
         <output sql="SELECT t_account_1.account_id, t_account_1.password, t_account_1.amount AS a, status AS s FROM t_account_1 WHERE t_account_1.account_id = 1 AND t_account_1.password = 'aaa' AND t_account_1.amount = 1000 AND t_account_1.status = 'OK'" />
     </rewrite-assertion>
+    
+    <rewrite-assertion id="select_with_join_table_with_qualified_columns">
+        <input sql="SELECT * FROM t_account, t_account_detail WHERE t_account.account_id = 1 AND t_account.account_id = t_account_detail.account_id" />
+        <output sql="SELECT * FROM t_account_1, t_account_detail_1 WHERE t_account_1.account_id = 1 AND t_account_1.account_id = t_account_detail_1.account_id" />
+    </rewrite-assertion>
 </rewrite-assertions>
diff --git a/sharding-core/sharding-core-rewrite/src/test/resources/yaml/sharding/sharding-rule.yaml b/sharding-core/sharding-core-rewrite/src/test/resources/yaml/sharding/sharding-rule.yaml
index cebbef8afd7..3f191b9004c 100644
--- a/sharding-core/sharding-core-rewrite/src/test/resources/yaml/sharding/sharding-rule.yaml
+++ b/sharding-core/sharding-core-rewrite/src/test/resources/yaml/sharding/sharding-rule.yaml
@@ -37,7 +37,7 @@ shardingRule:
       actualDataNodes: db.t_account_detail_${0..1}
       tableStrategy: 
         inline:
-          shardingColumn: order_id
+          shardingColumn: account_id
           algorithmExpression: t_account_detail_${account_id % 2}
   bindingTables:
     - t_account, t_account_detail
diff --git a/sharding-sql-test/src/main/resources/sql/supported/ddl/alter.xml b/sharding-sql-test/src/main/resources/sql/supported/ddl/alter.xml
index a6c99e0fb4e..415c7847a82 100644
--- a/sharding-sql-test/src/main/resources/sql/supported/ddl/alter.xml
+++ b/sharding-sql-test/src/main/resources/sql/supported/ddl/alter.xml
@@ -25,12 +25,16 @@
     <sql-case id="alter_table_with_back_quota" value="ALTER TABLE `t_order` FORCE" db-types="MySQL" />
     <sql-case id="alter_table_add_column" value="ALTER TABLE t_order ADD column4 VARCHAR(10)" />
     <sql-case id="alter_table_add_columns" value="ALTER TABLE t_order ADD column4 VARCHAR(10), ADD column5 VARCHAR(10), ADD column6 VARCHAR(10)" db-types="MySQL,PostgreSQL" />
-    <sql-case id="alter_table_add_columns_integer_type_mysql" value="ALTER TABLE t_order ADD column4 INTEGER, ADD column5 INT, ADD column6 SMALLINT, ADD column7 TINYINT, ADD column8 MEDIUMINT, ADD column9 BIGINT" db-types="MySQL" />
-    <sql-case id="alter_table_add_columns_fixed_point_type_mysql" value="ALTER TABLE t_order ADD column4 decimal(10,2), ADD column5 NUMERIC" db-types="MySQL" />
+    <sql-case id="alter_table_add_columns_integer_type_mysql" value="ALTER TABLE t_order ADD column4 TINYINT, ADD column5 MEDIUMINT" db-types="MySQL" />
+    <sql-case id="alter_table_add_columns_fixed_point_type" value="ALTER TABLE t_order ADD column4 decimal(10,2), ADD column5 NUMERIC" db-types="MySQL,PostgreSQL" />
     <sql-case id="alter_table_add_columns_float_point_type_mysql" value="ALTER TABLE t_order ADD column4 FLOAT(10,2), ADD column5 DOUBLE(10,2)" db-types="MySQL" />
     <sql-case id="alter_table_add_columns_bit_type_mysql" value="ALTER TABLE t_order ADD column4 bit" db-types="MySQL" />
-    <sql-case id="alter_table_add_columns_date_type_mysql" value="ALTER TABLE t_order ADD column4 DATE, ADD column5 DATETIME, ADD column6 TIMESTAMP, ADD column7 TIME, ADD column8 YEAR" db-types="MySQL" />
+    <sql-case id="alter_table_add_columns_date_type_mysql" value="ALTER TABLE t_order ADD column4 YEAR" db-types="MySQL" />
+    <sql-case id="alter_table_add_columns_date_type" value="ALTER TABLE t_order ADD column4 DATE, ADD column5 DATETIME, ADD column6 TIMESTAMP, ADD column7 TIME" db-types="MySQL,PostgreSQL" />
     <sql-case id="alter_table_add_columns_string_type_mysql" value="ALTER TABLE t_order ADD column4 CHAR, ADD column5 VARCHAR, ADD column6 BINARY, ADD column7 VARBINARY, ADD column8 TINYBLOB, ADD column9 TINYTEXT, ADD column10 BLOB, ADD column11 TEXT, ADD column12 MEDIUMBLOB, ADD column13 MEDIUMTEXT, ADD column14 LONGBLOB, ADD column15 LONGTEXT, ADD column16 ENUM, ADD column17 SET" db-types="MySQL" />
+    <sql-case id="alter_table_add_columns_integer_type" value="ALTER TABLE t_order ADD column4 INTEGER, ADD column5 INT, ADD column6 SMALLINT, ADD column7 BIGINT" db-types="MySQL,PostgreSQL" />
+    <sql-case id="alter_table_add_columns_float_point_type_postgresql" value="ALTER TABLE t_order ADD column4 FLOAT, ADD column5 double precision, ADD column6 REAL, ADD column7 SMALLSERIAL, ADD column8 SERIAL, ADD column9 BIGSERIAL, ADD column10 float4" db-types="PostgreSQL" />
+    <sql-case id="alter_table_add_columns_string_type_postgresql" value="ALTER TABLE t_order ADD column4 VARCHAR, ADD column5 CHARACTER, ADD column6 CHAR, ADD column7 TEXT, ADD column8 NAME" db-types="PostgreSQL" />
     <sql-case id="alter_table_add_column_with_first" value="ALTER TABLE t_order ADD column3 VARCHAR(10) FIRST" db-types="MySQL" />
     <sql-case id="alter_table_add_column_with_after" value="ALTER TABLE t_order ADD column4 VARCHAR(10) AFTER order_id" db-types="MySQL" />
     <sql-case id="alter_table_add_column_with_first_after" value="ALTER TABLE t_order ADD column5 VARCHAR(10) FIRST, ADD column6 VARCHAR(10) FIRST, ADD column7 VARCHAR(10) AFTER column5, ADD column8 VARCHAR(10) AFTER column6" db-types="MySQL" />
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/statement/dml/DeleteStatement.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/statement/dml/DeleteStatement.java
index 90d8a9e0f46..d62c95b1da5 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/statement/dml/DeleteStatement.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/statement/dml/DeleteStatement.java
@@ -20,6 +20,9 @@ package org.apache.shardingsphere.sql.parser.sql.statement.dml;
 import com.google.common.base.Optional;
 import lombok.Getter;
 import lombok.Setter;
+import org.apache.shardingsphere.sql.parser.sql.predicate.PredicateExtractor;
+import org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.AndPredicate;
+import org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.PredicateSegment;
 import org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.WhereSegment;
 import org.apache.shardingsphere.sql.parser.sql.segment.generic.TableSegment;
 import org.apache.shardingsphere.sql.parser.sql.statement.generic.TableSegmentsAvailable;
@@ -40,12 +43,26 @@ public final class DeleteStatement extends DMLStatement implements TableSegments
     private WhereSegment where;
     
     @Override
-    public Collection<TableSegment> getAllTables() {
-        return tables;
+    public Optional<WhereSegment> getWhere() {
+        return Optional.fromNullable(where);
     }
     
     @Override
-    public Optional<WhereSegment> getWhere() {
-        return Optional.fromNullable(where);
+    public Collection<TableSegment> getAllTables() {
+        Collection<TableSegment> result = new LinkedList<>(tables);
+        if (null != where) {
+            result.addAll(getAllTablesFromWhere());
+        }
+        return result;
+    }
+    
+    private Collection<TableSegment> getAllTablesFromWhere() {
+        Collection<TableSegment> result = new LinkedList<>();
+        for (AndPredicate each : where.getAndPredicates()) {
+            for (PredicateSegment predicate : each.getPredicates()) {
+                result.addAll(new PredicateExtractor(tables, predicate).extractTables());
+            }
+        }
+        return result;
     }
 }
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/statement/dml/UpdateStatement.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/statement/dml/UpdateStatement.java
index 4d0481dbffa..417ff0632bf 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/statement/dml/UpdateStatement.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/statement/dml/UpdateStatement.java
@@ -20,7 +20,10 @@ package org.apache.shardingsphere.sql.parser.sql.statement.dml;
 import com.google.common.base.Optional;
 import lombok.Getter;
 import lombok.Setter;
+import org.apache.shardingsphere.sql.parser.sql.predicate.PredicateExtractor;
 import org.apache.shardingsphere.sql.parser.sql.segment.dml.assignment.SetAssignmentSegment;
+import org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.AndPredicate;
+import org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.PredicateSegment;
 import org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.WhereSegment;
 import org.apache.shardingsphere.sql.parser.sql.segment.generic.TableSegment;
 import org.apache.shardingsphere.sql.parser.sql.statement.generic.TableSegmentsAvailable;
@@ -43,12 +46,26 @@ public final class UpdateStatement extends DMLStatement implements TableSegments
     private WhereSegment where;
     
     @Override
-    public Collection<TableSegment> getAllTables() {
-        return tables;
+    public Optional<WhereSegment> getWhere() {
+        return Optional.fromNullable(where);
     }
     
     @Override
-    public Optional<WhereSegment> getWhere() {
-        return Optional.fromNullable(where);
+    public Collection<TableSegment> getAllTables() {
+        Collection<TableSegment> result = new LinkedList<>(tables);
+        if (null != where) {
+            result.addAll(getAllTablesFromWhere());
+        }
+        return result;
+    }
+    
+    private Collection<TableSegment> getAllTablesFromWhere() {
+        Collection<TableSegment> result = new LinkedList<>();
+        for (AndPredicate each : where.getAndPredicates()) {
+            for (PredicateSegment predicate : each.getPredicates()) {
+                result.addAll(new PredicateExtractor(tables, predicate).extractTables());
+            }
+        }
+        return result;
     }
 }
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-relation/src/test/java/org/apache/shardingsphere/sql/parser/relation/segment/table/TablesContextTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-relation/src/test/java/org/apache/shardingsphere/sql/parser/relation/segment/table/TablesContextTest.java
index dc7bcaae43f..9909a78d8a2 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-relation/src/test/java/org/apache/shardingsphere/sql/parser/relation/segment/table/TablesContextTest.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-relation/src/test/java/org/apache/shardingsphere/sql/parser/relation/segment/table/TablesContextTest.java
@@ -51,7 +51,7 @@ public final class TablesContextTest {
     @Test
     public void assertIsNotEmpty() {
         SelectStatement selectStatement = new SelectStatement();
-        selectStatement.getAllTables().add(createTableSegment("table", "tbl"));
+        selectStatement.getTables().add(createTableSegment("table", "tbl"));
         TablesContext tablesContext = new TablesContext(selectStatement);
         assertFalse(tablesContext.isEmpty());
     }
@@ -59,7 +59,7 @@ public final class TablesContextTest {
     @Test
     public void assertIsSingleTable() {
         SelectStatement selectStatement = new SelectStatement();
-        selectStatement.getAllTables().add(createTableSegment("table", "tbl"));
+        selectStatement.getTables().add(createTableSegment("table", "tbl"));
         TablesContext tablesContext = new TablesContext(selectStatement);
         assertTrue(tablesContext.isSingleTable());
     }
@@ -67,8 +67,8 @@ public final class TablesContextTest {
     @Test
     public void assertIsSingleTableWithCaseSensitiveNames() {
         SelectStatement selectStatement = new SelectStatement();
-        selectStatement.getAllTables().add(createTableSegment("table", "tbl"));
-        selectStatement.getAllTables().add(createTableSegment("Table", null));
+        selectStatement.getTables().add(createTableSegment("table", "tbl"));
+        selectStatement.getTables().add(createTableSegment("Table", null));
         TablesContext tablesContext = new TablesContext(selectStatement);
         assertTrue(tablesContext.isSingleTable());
     }
@@ -76,8 +76,8 @@ public final class TablesContextTest {
     @Test
     public void assertIsSingleTableWithNameConflictAlias() {
         SelectStatement selectStatement = new SelectStatement();
-        selectStatement.getAllTables().add(createTableSegment("table", "tbl"));
-        selectStatement.getAllTables().add(createTableSegment("tbl", null));
+        selectStatement.getTables().add(createTableSegment("table", "tbl"));
+        selectStatement.getTables().add(createTableSegment("tbl", null));
         TablesContext tablesContext = new TablesContext(selectStatement);
         assertTrue(tablesContext.isSingleTable());
     }
@@ -85,8 +85,8 @@ public final class TablesContextTest {
     @Test
     public void assertIsNotSingleTable() {
         SelectStatement selectStatement = new SelectStatement();
-        selectStatement.getAllTables().add(createTableSegment("table_1", "tbl_1"));
-        selectStatement.getAllTables().add(createTableSegment("table_2", "tbl_2"));
+        selectStatement.getTables().add(createTableSegment("table_1", "tbl_1"));
+        selectStatement.getTables().add(createTableSegment("table_2", "tbl_2"));
         TablesContext tablesContext = new TablesContext(selectStatement);
         assertFalse(tablesContext.isSingleTable());
     }
@@ -94,7 +94,7 @@ public final class TablesContextTest {
     @Test
     public void assertGetSingleTableName() {
         SelectStatement selectStatement = new SelectStatement();
-        selectStatement.getAllTables().add(createTableSegment("table", "tbl"));
+        selectStatement.getTables().add(createTableSegment("table", "tbl"));
         TablesContext tablesContext = new TablesContext(selectStatement);
         assertThat(tablesContext.getSingleTableName(), is("table"));
     }
@@ -102,8 +102,8 @@ public final class TablesContextTest {
     @Test
     public void assertGetTableNames() {
         SelectStatement selectStatement = new SelectStatement();
-        selectStatement.getAllTables().add(createTableSegment("table_1", "tbl_1"));
-        selectStatement.getAllTables().add(createTableSegment("table_2", "tbl_2"));
+        selectStatement.getTables().add(createTableSegment("table_1", "tbl_1"));
+        selectStatement.getTables().add(createTableSegment("table_2", "tbl_2"));
         TablesContext tablesContext = new TablesContext(selectStatement);
         assertThat(tablesContext.getTableNames(), CoreMatchers.<Collection<String>>is(Sets.newHashSet("table_1", "table_2")));
     }
@@ -111,8 +111,8 @@ public final class TablesContextTest {
     @Test
     public void assertFindTableWithName() {
         SelectStatement selectStatement = new SelectStatement();
-        selectStatement.getAllTables().add(createTableSegment("table_1", "tbl_1"));
-        selectStatement.getAllTables().add(createTableSegment("table_2", "tbl_2"));
+        selectStatement.getTables().add(createTableSegment("table_1", "tbl_1"));
+        selectStatement.getTables().add(createTableSegment("table_2", "tbl_2"));
         TablesContext tablesContext = new TablesContext(selectStatement);
         Optional<Table> table = tablesContext.find("table_1");
         assertTrue(table.isPresent());
@@ -123,8 +123,8 @@ public final class TablesContextTest {
     @Test
     public void assertFindTableWithAlias() {
         SelectStatement selectStatement = new SelectStatement();
-        selectStatement.getAllTables().add(createTableSegment("table_1", "tbl_1"));
-        selectStatement.getAllTables().add(createTableSegment("table_2", "tbl_2"));
+        selectStatement.getTables().add(createTableSegment("table_1", "tbl_1"));
+        selectStatement.getTables().add(createTableSegment("table_2", "tbl_2"));
         TablesContext tablesContext = new TablesContext(selectStatement);
         Optional<Table> table = tablesContext.find("tbl_1");
         assertTrue(table.isPresent());
@@ -135,8 +135,8 @@ public final class TablesContextTest {
     @Test
     public void assertNotFoundTable() {
         SelectStatement selectStatement = new SelectStatement();
-        selectStatement.getAllTables().add(createTableSegment("table_1", "tbl_1"));
-        selectStatement.getAllTables().add(createTableSegment("table_2", "tbl_2"));
+        selectStatement.getTables().add(createTableSegment("table_1", "tbl_1"));
+        selectStatement.getTables().add(createTableSegment("table_2", "tbl_2"));
         TablesContext tablesContext = new TablesContext(selectStatement);
         Optional<Table> table = tablesContext.find("table_3");
         assertFalse(table.isPresent());
@@ -145,15 +145,15 @@ public final class TablesContextTest {
     @Test
     public void assertFindTableNameWhenSingleTable() {
         SelectStatement selectStatement = new SelectStatement();
-        selectStatement.getAllTables().add(createTableSegment("table_1", "tbl_1"));
+        selectStatement.getTables().add(createTableSegment("table_1", "tbl_1"));
         assertTrue(new TablesContext(selectStatement).findTableName(null, null).isPresent());
     }
     
     @Test
     public void assertFindTableNameWhenColumnSegmentOwnerPresent() {
         SelectStatement selectStatement = new SelectStatement();
-        selectStatement.getAllTables().add(createTableSegment("table_1", "tbl_1"));
-        selectStatement.getAllTables().add(createTableSegment("table_2", "tbl_2"));
+        selectStatement.getTables().add(createTableSegment("table_1", "tbl_1"));
+        selectStatement.getTables().add(createTableSegment("table_2", "tbl_2"));
         TablesContext tablesContext = new TablesContext(selectStatement);
         ColumnSegment columnSegment = mock(ColumnSegment.class);
         when(columnSegment.getOwner()).thenReturn(Optional.of(new OwnerSegment(0, 10, new IdentifierValue("table_1"))));
@@ -163,8 +163,8 @@ public final class TablesContextTest {
     @Test
     public void assertFindTableNameWhenColumnSegmentOwnerAbsent() {
         SelectStatement selectStatement = new SelectStatement();
-        selectStatement.getAllTables().add(createTableSegment("table_1", "tbl_1"));
-        selectStatement.getAllTables().add(createTableSegment("table_2", "tbl_2"));
+        selectStatement.getTables().add(createTableSegment("table_1", "tbl_1"));
+        selectStatement.getTables().add(createTableSegment("table_2", "tbl_2"));
         TablesContext tablesContext = new TablesContext(selectStatement);
         ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("col"));
         RelationMetas relationMetas = mock(RelationMetas.class);
@@ -174,8 +174,8 @@ public final class TablesContextTest {
     @Test
     public void assertFindTableNameWhenColumnSegmentOwnerAbsentAndRelationMetasContainsColumn() {
         SelectStatement selectStatement = new SelectStatement();
-        selectStatement.getAllTables().add(createTableSegment("table_1", "tbl_1"));
-        selectStatement.getAllTables().add(createTableSegment("table_2", "tbl_2"));
+        selectStatement.getTables().add(createTableSegment("table_1", "tbl_1"));
+        selectStatement.getTables().add(createTableSegment("table_2", "tbl_2"));
         ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("col"));
         RelationMetas relationMetas = mock(RelationMetas.class);
         when(relationMetas.containsColumn(anyString(), anyString())).thenReturn(true);
@@ -185,7 +185,7 @@ public final class TablesContextTest {
     @Test
     public void assertGetSchema() {
         SelectStatement selectStatement = new SelectStatement();
-        selectStatement.getAllTables().add(createTableSegment("table_1", "tbl_1"));
+        selectStatement.getTables().add(createTableSegment("table_1", "tbl_1"));
         assertFalse(new TablesContext(selectStatement).getSchema().isPresent());
     }
     
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/ddl/alter-table.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/ddl/alter-table.xml
index 4cca4b4f95d..2c92e0031db 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/ddl/alter-table.xml
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/ddl/alter-table.xml
@@ -78,38 +78,42 @@
     <alter-table sql-case-id="alter_table_add_columns_integer_type_mysql">
         <table name="t_order" start-index="12" stop-index="18" />
         <add-column>
-            <column-definition type="INTEGER">
+            <column-definition type="TINYINT">
                 <column name="column4" />
             </column-definition>
         </add-column>
         <add-column>
-            <column-definition type="INT">
+            <column-definition type="MEDIUMINT">
                 <column name="column5" />
             </column-definition>
         </add-column>
+    </alter-table>
+
+    <alter-table sql-case-id="alter_table_add_columns_integer_type">
+        <table name="t_order" start-index="12" stop-index="18" />
         <add-column>
-            <column-definition type="SMALLINT">
-                <column name="column6" />
+            <column-definition type="INTEGER">
+                <column name="column4" />
             </column-definition>
         </add-column>
         <add-column>
-            <column-definition type="TINYINT">
-                <column name="column7" />
+            <column-definition type="INT">
+                <column name="column5" />
             </column-definition>
         </add-column>
         <add-column>
-            <column-definition type="MEDIUMINT">
-                <column name="column8" />
+            <column-definition type="SMALLINT">
+                <column name="column6" />
             </column-definition>
         </add-column>
         <add-column>
             <column-definition type="BIGINT">
-                <column name="column9" />
+                <column name="column7" />
             </column-definition>
         </add-column>
     </alter-table>
 
-    <alter-table sql-case-id="alter_table_add_columns_fixed_point_type_mysql">
+    <alter-table sql-case-id="alter_table_add_columns_fixed_point_type">
         <table name="t_order" start-index="12" stop-index="18" />
         <add-column>
             <column-definition type="decimal">
@@ -137,42 +141,61 @@
         </add-column>
     </alter-table>
 
-    <alter-table sql-case-id="alter_table_add_columns_bit_type_mysql">
+    <alter-table sql-case-id="alter_table_add_columns_float_point_type_postgresql">
         <table name="t_order" start-index="12" stop-index="18" />
         <add-column>
-            <column-definition type="bit">
-                <column name="column4" />
-            </column-definition>
-        </add-column>
-    </alter-table>
-
-    <alter-table sql-case-id="alter_table_add_columns_date_type_mysql">
-        <table name="t_order" start-index="12" stop-index="18" />
-        <add-column>
-            <column-definition type="DATE">
+            <column-definition type="FLOAT">
                 <column name="column4" />
             </column-definition>
         </add-column>
         <add-column>
-            <column-definition type="DATETIME">
+            <column-definition type="double precision">
                 <column name="column5" />
             </column-definition>
         </add-column>
         <add-column>
-            <column-definition type="TIMESTAMP">
+            <column-definition type="REAL">
                 <column name="column6" />
             </column-definition>
         </add-column>
         <add-column>
-            <column-definition type="TIME">
+            <column-definition type="SMALLSERIAL">
                 <column name="column7" />
             </column-definition>
         </add-column>
         <add-column>
-            <column-definition type="YEAR">
+            <column-definition type="SERIAL">
                 <column name="column8" />
             </column-definition>
         </add-column>
+        <add-column>
+            <column-definition type="BIGSERIAL">
+                <column name="column9" />
+            </column-definition>
+        </add-column>
+        <add-column>
+            <column-definition type="float4">
+                <column name="column10" />
+            </column-definition>
+        </add-column>
+    </alter-table>
+
+    <alter-table sql-case-id="alter_table_add_columns_bit_type_mysql">
+        <table name="t_order" start-index="12" stop-index="18" />
+        <add-column>
+            <column-definition type="bit">
+                <column name="column4" />
+            </column-definition>
+        </add-column>
+    </alter-table>
+
+    <alter-table sql-case-id="alter_table_add_columns_date_type_mysql">
+        <table name="t_order" start-index="12" stop-index="18" />
+        <add-column>
+            <column-definition type="YEAR">
+                <column name="column4" />
+            </column-definition>
+        </add-column>
     </alter-table>
 
     <alter-table sql-case-id="alter_table_add_columns_string_type_mysql">
@@ -248,7 +271,60 @@
             </column-definition>
         </add-column>
     </alter-table>
-    
+
+    <alter-table sql-case-id="alter_table_add_columns_string_type_postgresql">
+        <table name="t_order" start-index="12" stop-index="18" />
+        <add-column>
+            <column-definition type="VARCHAR">
+                <column name="column4" />
+            </column-definition>
+        </add-column>
+        <add-column>
+            <column-definition type="CHARACTER">
+                <column name="column5" />
+            </column-definition>
+        </add-column>
+        <add-column>
+            <column-definition type="CHAR">
+                <column name="column6" />
+            </column-definition>
+        </add-column>
+        <add-column>
+            <column-definition type="TEXT">
+                <column name="column7" />
+            </column-definition>
+        </add-column>
+        <add-column>
+            <column-definition type="NAME">
+                <column name="column8" />
+            </column-definition>
+        </add-column>
+    </alter-table>
+
+    <alter-table sql-case-id="alter_table_add_columns_date_type">
+        <table name="t_order" start-index="12" stop-index="18" />
+        <add-column>
+            <column-definition type="DATE">
+                <column name="column4" />
+            </column-definition>
+        </add-column>
+        <add-column>
+            <column-definition type="DATETIME">
+                <column name="column5" />
+            </column-definition>
+        </add-column>
+        <add-column>
+            <column-definition type="TIMESTAMP">
+                <column name="column6" />
+            </column-definition>
+        </add-column>
+        <add-column>
+            <column-definition type="TIME">
+                <column name="column7" />
+            </column-definition>
+        </add-column>
+    </alter-table>
+
     <alter-table sql-case-id="alter_table_add_column_with_first">
         <table name="t_order" start-index="12" stop-index="18" />
         <add-column>