Skip to content

Commit f29ce10

Browse files
frolovdevalamb
andauthored
Distinguish between INT and INTEGER types (apache#525)
* support integer * fmt * Update src/ast/data_type.rs Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org> Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
1 parent c884fbc commit f29ce10

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

src/ast/data_type.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ pub enum DataType {
5555
UnsignedSmallInt(Option<u64>),
5656
/// Integer with optional display width e.g. INT or INT(11)
5757
Int(Option<u64>),
58+
/// Integer with optional display width e.g. INTEGER or INTEGER(11)
59+
Integer(Option<u64>),
5860
/// Unsigned integer with optional display width e.g. INT UNSIGNED or INT(11) UNSIGNED
5961
UnsignedInt(Option<u64>),
62+
/// Unsigned integer with optional display width e.g. INTGER UNSIGNED or INTEGER(11) UNSIGNED
63+
UnsignedInteger(Option<u64>),
6064
/// Big integer with optional display width e.g. BIGINT or BIGINT(20)
6165
BigInt(Option<u64>),
6266
/// Unsigned big integer with optional display width e.g. BIGINT UNSIGNED or BIGINT(20) UNSIGNED
@@ -134,6 +138,12 @@ impl fmt::Display for DataType {
134138
DataType::UnsignedInt(zerofill) => {
135139
format_type_with_optional_length(f, "INT", zerofill, true)
136140
}
141+
DataType::Integer(zerofill) => {
142+
format_type_with_optional_length(f, "INTEGER", zerofill, false)
143+
}
144+
DataType::UnsignedInteger(zerofill) => {
145+
format_type_with_optional_length(f, "INTEGER", zerofill, true)
146+
}
137147
DataType::BigInt(zerofill) => {
138148
format_type_with_optional_length(f, "BIGINT", zerofill, false)
139149
}

src/parser.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2859,14 +2859,22 @@ impl<'a> Parser<'a> {
28592859
Ok(DataType::SmallInt(optional_precision?))
28602860
}
28612861
}
2862-
Keyword::INT | Keyword::INTEGER => {
2862+
Keyword::INT => {
28632863
let optional_precision = self.parse_optional_precision();
28642864
if self.parse_keyword(Keyword::UNSIGNED) {
28652865
Ok(DataType::UnsignedInt(optional_precision?))
28662866
} else {
28672867
Ok(DataType::Int(optional_precision?))
28682868
}
28692869
}
2870+
Keyword::INTEGER => {
2871+
let optional_precision = self.parse_optional_precision();
2872+
if self.parse_keyword(Keyword::UNSIGNED) {
2873+
Ok(DataType::UnsignedInteger(optional_precision?))
2874+
} else {
2875+
Ok(DataType::Integer(optional_precision?))
2876+
}
2877+
}
28702878
Keyword::BIGINT => {
28712879
let optional_precision = self.parse_optional_precision();
28722880
if self.parse_keyword(Keyword::UNSIGNED) {

tests/sqlparser_postgres.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn parse_create_table_with_defaults() {
3535
activebool boolean DEFAULT true NOT NULL,
3636
create_date date DEFAULT now()::text NOT NULL,
3737
last_update timestamp without time zone DEFAULT now() NOT NULL,
38-
active integer NOT NULL
38+
active int NOT NULL
3939
) WITH (fillfactor = 20, user_catalog_table = true, autovacuum_vacuum_threshold = 100)";
4040
match pg_and_generic().one_statement_parses_to(sql, "") {
4141
Statement::CreateTable {
@@ -55,7 +55,7 @@ fn parse_create_table_with_defaults() {
5555
vec![
5656
ColumnDef {
5757
name: "customer_id".into(),
58-
data_type: DataType::Int(None),
58+
data_type: DataType::Integer(None),
5959
collation: None,
6060
options: vec![ColumnOptionDef {
6161
name: None,
@@ -201,10 +201,10 @@ fn parse_create_table_from_pg_dump() {
201201
create_date1 date DEFAULT 'now'::TEXT::date NOT NULL,
202202
last_update timestamp without time zone DEFAULT now(),
203203
release_year public.year,
204-
active integer
204+
active int
205205
)";
206206
pg().one_statement_parses_to(sql, "CREATE TABLE public.customer (\
207-
customer_id INT DEFAULT nextval(CAST('public.customer_customer_id_seq' AS REGCLASS)) NOT NULL, \
207+
customer_id INTEGER DEFAULT nextval(CAST('public.customer_customer_id_seq' AS REGCLASS)) NOT NULL, \
208208
store_id SMALLINT NOT NULL, \
209209
first_name CHARACTER VARYING(45) NOT NULL, \
210210
last_name CHARACTER VARYING(45) NOT NULL, \

0 commit comments

Comments
 (0)