diff --git a/src/ast/data_type.rs b/src/ast/data_type.rs index fc8b98c5..53122ab5 100644 --- a/src/ast/data_type.rs +++ b/src/ast/data_type.rs @@ -72,36 +72,36 @@ pub enum DataType { impl fmt::Display for DataType { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - DataType::Char(size) => format_type_with_optional_length(f, "char", size), + DataType::Char(size) => format_type_with_optional_length(f, "CHAR", size), DataType::Varchar(size) => { - format_type_with_optional_length(f, "character varying", size) + format_type_with_optional_length(f, "CHARACTER VARYING", size) } - DataType::Uuid => write!(f, "uuid"), - DataType::Clob(size) => write!(f, "clob({})", size), - DataType::Binary(size) => write!(f, "binary({})", size), - DataType::Varbinary(size) => write!(f, "varbinary({})", size), - DataType::Blob(size) => write!(f, "blob({})", size), + DataType::Uuid => write!(f, "UUID"), + DataType::Clob(size) => write!(f, "CLOB({})", size), + DataType::Binary(size) => write!(f, "BINARY({})", size), + DataType::Varbinary(size) => write!(f, "VARBINARY({})", size), + DataType::Blob(size) => write!(f, "BLOB({})", size), DataType::Decimal(precision, scale) => { if let Some(scale) = scale { - write!(f, "numeric({},{})", precision.unwrap(), scale) + write!(f, "NUMERIC({},{})", precision.unwrap(), scale) } else { - format_type_with_optional_length(f, "numeric", precision) + format_type_with_optional_length(f, "NUMERIC", precision) } } - DataType::Float(size) => format_type_with_optional_length(f, "float", size), - DataType::SmallInt => write!(f, "smallint"), - DataType::Int => write!(f, "int"), - DataType::BigInt => write!(f, "bigint"), - DataType::Real => write!(f, "real"), - DataType::Double => write!(f, "double"), - DataType::Boolean => write!(f, "boolean"), - DataType::Date => write!(f, "date"), - DataType::Time => write!(f, "time"), - DataType::Timestamp => write!(f, "timestamp"), - DataType::Interval => write!(f, "interval"), - DataType::Regclass => write!(f, "regclass"), - DataType::Text => write!(f, "text"), - DataType::Bytea => write!(f, "bytea"), + DataType::Float(size) => format_type_with_optional_length(f, "FLOAT", size), + DataType::SmallInt => write!(f, "SMALLINT"), + DataType::Int => write!(f, "INT"), + DataType::BigInt => write!(f, "BIGINT"), + DataType::Real => write!(f, "REAL"), + DataType::Double => write!(f, "DOUBLE"), + DataType::Boolean => write!(f, "BOOLEAN"), + DataType::Date => write!(f, "DATE"), + DataType::Time => write!(f, "TIME"), + DataType::Timestamp => write!(f, "TIMESTAMP"), + DataType::Interval => write!(f, "INTERVAL"), + DataType::Regclass => write!(f, "REGCLASS"), + DataType::Text => write!(f, "TEXT"), + DataType::Bytea => write!(f, "BYTEA"), DataType::Array(ty) => write!(f, "{}[]", ty), DataType::Custom(ty) => write!(f, "{}", ty), } diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index 5599eab9..bff13133 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -908,7 +908,7 @@ fn parse_limit_accepts_all() { #[test] fn parse_cast() { - let sql = "SELECT CAST(id AS bigint) FROM customer"; + let sql = "SELECT CAST(id AS BIGINT) FROM customer"; let select = verified_only_select(sql); assert_eq!( &Expr::Cast { @@ -919,19 +919,19 @@ fn parse_cast() { ); one_statement_parses_to( "SELECT CAST(id AS BIGINT) FROM customer", - "SELECT CAST(id AS bigint) FROM customer", + "SELECT CAST(id AS BIGINT) FROM customer", ); - verified_stmt("SELECT CAST(id AS numeric) FROM customer"); + verified_stmt("SELECT CAST(id AS NUMERIC) FROM customer"); one_statement_parses_to( - "SELECT CAST(id AS dec) FROM customer", - "SELECT CAST(id AS numeric) FROM customer", + "SELECT CAST(id AS DEC) FROM customer", + "SELECT CAST(id AS NUMERIC) FROM customer", ); one_statement_parses_to( - "SELECT CAST(id AS decimal) FROM customer", - "SELECT CAST(id AS numeric) FROM customer", + "SELECT CAST(id AS DECIMAL) FROM customer", + "SELECT CAST(id AS NUMERIC) FROM customer", ); } @@ -1027,12 +1027,12 @@ fn parse_create_table() { let ast = one_statement_parses_to( sql, "CREATE TABLE uk_cities (\ - name character varying(100) NOT NULL, \ - lat double NULL, \ - lng double, \ - constrained int NULL CONSTRAINT pkey PRIMARY KEY NOT NULL UNIQUE CHECK (constrained > 0), \ - ref int REFERENCES othertable (a, b), \ - ref2 int REFERENCES othertable2 ON DELETE CASCADE ON UPDATE NO ACTION)", + name CHARACTER VARYING(100) NOT NULL, \ + lat DOUBLE NULL, \ + lng DOUBLE, \ + constrained INT NULL CONSTRAINT pkey PRIMARY KEY NOT NULL UNIQUE CHECK (constrained > 0), \ + ref INT REFERENCES othertable (a, b), \ + ref2 INT REFERENCES othertable2 ON DELETE CASCADE ON UPDATE NO ACTION)", ); match ast { Statement::CreateTable { @@ -1193,7 +1193,7 @@ fn parse_create_table_with_on_delete_on_update_2in_any_order() -> Result<(), Par #[test] fn parse_create_table_with_options() { - let sql = "CREATE TABLE t (c int) WITH (foo = 'bar', a = 123)"; + let sql = "CREATE TABLE t (c INT) WITH (foo = 'bar', a = 123)"; match verified_stmt(sql) { Statement::CreateTable { with_options, .. } => { assert_eq!( @@ -1217,7 +1217,7 @@ fn parse_create_table_with_options() { #[test] fn parse_create_table_trailing_comma() { let sql = "CREATE TABLE foo (bar int,)"; - all_dialects().one_statement_parses_to(sql, "CREATE TABLE foo (bar int)"); + all_dialects().one_statement_parses_to(sql, "CREATE TABLE foo (bar INT)"); } #[test] @@ -1230,9 +1230,9 @@ fn parse_create_external_table() { let ast = one_statement_parses_to( sql, "CREATE EXTERNAL TABLE uk_cities (\ - name character varying(100) NOT NULL, \ - lat double NULL, \ - lng double) \ + name CHARACTER VARYING(100) NOT NULL, \ + lat DOUBLE NULL, \ + lng DOUBLE) \ STORED AS TEXTFILE LOCATION '/tmp/example.csv'", ); match ast { @@ -1299,9 +1299,9 @@ fn parse_create_external_table_lowercase() { let ast = one_statement_parses_to( sql, "CREATE EXTERNAL TABLE uk_cities (\ - name character varying(100) NOT NULL, \ - lat double NULL, \ - lng double) \ + name CHARACTER VARYING(100) NOT NULL, \ + lat DOUBLE NULL, \ + lng DOUBLE) \ STORED AS PARQUET LOCATION '/tmp/example.csv'", ); assert_matches!(ast, Statement::CreateTable{..}); @@ -1339,7 +1339,7 @@ fn parse_alter_table_constraints() { } _ => unreachable!(), } - verified_stmt(&format!("CREATE TABLE foo (id int, {})", constraint_text)); + verified_stmt(&format!("CREATE TABLE foo (id INT, {})", constraint_text)); } } @@ -1457,7 +1457,7 @@ fn parse_literal_string() { #[test] fn parse_literal_date() { - let sql = "SELECT date '1999-01-01'"; + let sql = "SELECT DATE '1999-01-01'"; let select = verified_only_select(sql); assert_eq!( &Expr::TypedString { @@ -1470,7 +1470,7 @@ fn parse_literal_date() { #[test] fn parse_literal_time() { - let sql = "SELECT time '01:23:34'"; + let sql = "SELECT TIME '01:23:34'"; let select = verified_only_select(sql); assert_eq!( &Expr::TypedString { @@ -1483,7 +1483,7 @@ fn parse_literal_time() { #[test] fn parse_literal_timestamp() { - let sql = "SELECT timestamp '1999-01-01 01:23:34'"; + let sql = "SELECT TIMESTAMP '1999-01-01 01:23:34'"; let select = verified_only_select(sql); assert_eq!( &Expr::TypedString { @@ -2289,7 +2289,7 @@ fn parse_multiple_statements() { ); test_with("DELETE FROM foo", "SELECT", " bar"); test_with("INSERT INTO foo VALUES (1)", "SELECT", " bar"); - test_with("CREATE TABLE foo (baz int)", "SELECT", " bar"); + test_with("CREATE TABLE foo (baz INT)", "SELECT", " bar"); // Make sure that empty statements do not cause an error: let res = parse_sql_statements(";;"); assert_eq!(0, res.unwrap().len()); diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs index bd467dc7..88e94d01 100644 --- a/tests/sqlparser_postgres.rs +++ b/tests/sqlparser_postgres.rs @@ -124,7 +124,7 @@ fn parse_create_table_with_defaults() { ColumnOptionDef { name: None, option: ColumnOption::Default( - pg().verified_expr("CAST(now() AS text)") + pg().verified_expr("CAST(now() AS TEXT)") ) }, ColumnOptionDef { @@ -192,25 +192,25 @@ fn parse_create_table_from_pg_dump() { info text[], address_id smallint NOT NULL, activebool boolean DEFAULT true NOT NULL, - create_date date DEFAULT now()::date NOT NULL, - create_date1 date DEFAULT 'now'::text::date NOT NULL, + create_date date DEFAULT now()::DATE NOT NULL, + create_date1 date DEFAULT 'now'::TEXT::date NOT NULL, last_update timestamp without time zone DEFAULT now(), release_year public.year, active integer )"; pg().one_statement_parses_to(sql, "CREATE TABLE public.customer (\ - customer_id int DEFAULT nextval(CAST('public.customer_customer_id_seq' AS regclass)) NOT NULL, \ - store_id smallint NOT NULL, \ - first_name character varying(45) NOT NULL, \ - last_name character varying(45) NOT NULL, \ - info text[], \ - address_id smallint NOT NULL, \ - activebool boolean DEFAULT true NOT NULL, \ - create_date date DEFAULT CAST(now() AS date) NOT NULL, \ - create_date1 date DEFAULT CAST(CAST('now' AS text) AS date) NOT NULL, \ - last_update timestamp DEFAULT now(), \ + customer_id INT DEFAULT nextval(CAST('public.customer_customer_id_seq' AS REGCLASS)) NOT NULL, \ + store_id SMALLINT NOT NULL, \ + first_name CHARACTER VARYING(45) NOT NULL, \ + last_name CHARACTER VARYING(45) NOT NULL, \ + info TEXT[], \ + address_id SMALLINT NOT NULL, \ + activebool BOOLEAN DEFAULT true NOT NULL, \ + create_date DATE DEFAULT CAST(now() AS DATE) NOT NULL, \ + create_date1 DATE DEFAULT CAST(CAST('now' AS TEXT) AS DATE) NOT NULL, \ + last_update TIMESTAMP DEFAULT now(), \ release_year public.year, \ - active int\ + active INT\ )"); } @@ -218,10 +218,10 @@ fn parse_create_table_from_pg_dump() { fn parse_create_table_with_inherit() { let sql = "\ CREATE TABLE bazaar.settings (\ - settings_id uuid PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL, \ - user_id uuid UNIQUE, \ - value text[], \ - use_metric boolean DEFAULT true\ + settings_id UUID PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL, \ + user_id UUID UNIQUE, \ + value TEXT[], \ + use_metric BOOLEAN DEFAULT true\ )"; pg().verified_stmt(sql); }