Map SQL Numeric Types to Prisma Int, Float, Decimal, and BigInt

Learn how SQL INTEGER, BIGINT, DECIMAL, FLOAT, and DOUBLE PRECISION columns translate to Prisma numeric scalar types with native database annotations.

Field Types

Detailed Explanation

Numeric Type Mapping

SQL has a rich set of numeric types with different ranges and precision. Prisma provides four numeric scalar types: Int, BigInt, Float, and Decimal. The converter selects the appropriate type based on the SQL column definition.

Example SQL

CREATE TABLE products (
  id SERIAL PRIMARY KEY,
  quantity INTEGER NOT NULL DEFAULT 0,
  views BIGINT NOT NULL DEFAULT 0,
  price DECIMAL(10, 2) NOT NULL,
  weight DOUBLE PRECISION,
  rating REAL
);

Generated Prisma Schema

model Product {
  id       Int      @id @default(autoincrement())
  quantity Int      @default(0)
  views    BigInt   @default(0)
  price    Decimal  @db.Decimal(10, 2)
  weight   Float?   @db.DoublePrecision
  rating   Float?   @db.Real

  @@map("products")
}

Type Mapping Table

SQL type Prisma type Notes
INTEGER / INT Int 32-bit signed integer
SMALLINT Int @db.SmallInt annotation
BIGINT / BIGSERIAL BigInt 64-bit, serialized as string in JSON
DECIMAL(p,s) / NUMERIC(p,s) Decimal Exact precision for money
REAL / FLOAT4 Float @db.Real — 32-bit floating point
DOUBLE PRECISION / FLOAT8 Float @db.DoublePrecision — 64-bit
MONEY Decimal PostgreSQL-specific

Decimal for Money

Always use Decimal (not Float) for monetary values. Floating-point arithmetic introduces rounding errors that accumulate over many transactions. The Decimal type in Prisma maps to a JavaScript Decimal.js instance in the client, providing exact arithmetic.

price    Decimal @db.Decimal(10, 2)
discount Decimal @db.Decimal(5, 2)
tax      Decimal @db.Decimal(10, 2)

BigInt Serialization

BigInt fields are serialized as strings in JSON because JavaScript Number cannot safely represent integers larger than 2^53 - 1. When consuming BigInt values via the Prisma client, remember to handle the string representation in your API responses.

Default Values

Numeric defaults map directly:

SQL default Prisma default
DEFAULT 0 @default(0)
DEFAULT 1.5 @default(1.5)
DEFAULT nextval('seq') @default(autoincrement())

Unsigned Integers (MySQL)

MySQL supports UNSIGNED integers. Prisma does not have a native unsigned type, so the converter uses @db.UnsignedInt, @db.UnsignedBigInt, etc., to preserve the database constraint.

Use Case

You are converting a financial application's SQL schema where prices use DECIMAL(10,2), analytics counters use BIGINT, and measurements use DOUBLE PRECISION. The converter maps each to the correct Prisma type preserving precision and range.

Try It — SQL to Prisma Schema

Open full tool