Toolvito

Works on this device

SQL Data Type Converter

Change a column type from one database engine to another: the nearest type in PostgreSQL, MySQL, SQL Server, Oracle and SQLite, with a warning where values could be lost. Convert the column list of a CREATE TABLE in one step, or write a CAST and see what each engine returns for your value. No SQL is run.

Enter your values

Type a column type as one engine writes it. You get the nearest type in each engine, with a warning where values could be lost.

Your values

As it is written in the CREATE TABLE, such as DECIMAL(10,2), VARCHAR2(50 CHAR), TINYINT UNSIGNED or datetime2(3).

Your values are worked out in this browser. They are not sent to a server.

Your result will show here

Fill in the values, then choose Convert.

How to use the converter

  1. Choose a task. One column type in every engine is the first choice.
  2. Pick the engine the type comes from and type the type as it is written, such as NVARCHAR(100), DECIMAL(10,2) or VARCHAR2(50 CHAR).
  3. Choose Convert. The table gives the nearest type in each engine and says where values can be lost.
  4. To convert many columns, choose A column list from one engine to another and paste the lines of your CREATE TABLE. To change a value, choose CAST or CONVERT a value to another type.

Common mappings

Nearest types (the tool gives the details and warnings)
Kind PostgreSQL MySQL SQL Server Oracle SQLite
Whole number (4 bytes) integer INT int NUMBER(10) INTEGER
Big whole number bigint BIGINT bigint NUMBER(19) INTEGER
Exact decimal numeric(p,s) DECIMAL(p,s) decimal(p,s) NUMBER(p,s) NUMERIC (not exact)
Floating point double precision DOUBLE float BINARY_DOUBLE REAL
Text up to n characters varchar(n) VARCHAR(n) nvarchar(n) VARCHAR2(n CHAR) TEXT
Long text text LONGTEXT nvarchar(max) CLOB TEXT
True or false boolean BOOLEAN (TINYINT(1)) bit BOOLEAN (23ai) INTEGER
Date and time timestamp DATETIME datetime2 TIMESTAMP TEXT
Date, time and zone timestamptz no such type datetimeoffset TIMESTAMP WITH TIME ZONE TEXT
UUID uuid BINARY(16) uniqueidentifier RAW(16) TEXT
JSON jsonb JSON nvarchar(max) + ISJSON check JSON (21c and later) TEXT

Worked examples

One type: SQL Server NVARCHAR(100) is varchar(100) in PostgreSQL, VARCHAR(100) in MySQL, VARCHAR2(100 CHAR) in Oracle and TEXT in SQLite, which does not check the length.

JSON in SQL Server: SQL Server 2019 and 2022 have no JSON type. Keep JSON in nvarchar(max) with CHECK (ISJSON(col) = 1). PostgreSQL has jsonb, MySQL JSON, Oracle JSON from 21c.

CAST of a decimal: CAST(12.75 AS int) is 12 in SQL Server and SQLite, which cut off the decimal part, and 13 in PostgreSQL, MySQL and Oracle, which round.

Text to a number: CAST('12.5' AS int) stops with an error in SQL Server and PostgreSQL, gives 12 with a warning in MySQL, 12 in SQLite and 13 in Oracle.

What a lossy mapping is

  • A smaller range: MySQL TINYINT (-128 to 127) does not fit SQL Server tinyint (0 to 255), so smallint is given.
  • Fewer digits: MySQL DECIMAL has at most 65 digits and SQL Server decimal 38.
  • Fewer fraction digits: SQL Server datetime2(7) keeps 100 nanoseconds; PostgreSQL and MySQL keep microseconds.
  • A lost time zone: MySQL has no type that keeps the offset of datetimeoffset or timestamptz.
  • A length that counts something else: SQL Server varchar(n) and Oracle VARCHAR2(n BYTE) count bytes, the others count characters.

Other tools for the same subject

Limits you should know

  • Spatial types, arrays, ranges and user-defined types are not converted.
  • In a column list only the types and identity columns change. Defaults, functions and CHECK rules are copied as written.
  • CAST results are shown only where the engine documents them; a float is not rounded here to a decimal or turned into text, because engines write floats in different ways.
  • No SQL is run. Test the new table and the CAST in your own database version.

Related tools