Prisma Number Types to SQL INTEGER, BIGINT, FLOAT, and DECIMAL

Learn how Prisma Int, BigInt, Float, and Decimal fields map to SQL numeric types. Covers differences between PostgreSQL, MySQL, and SQLite dialects.

Field Types

Detailed Explanation

Numeric Type Mapping

Prisma provides four numeric scalar types that map to different SQL column types based on precision and range requirements.

Default Mappings

Prisma type PostgreSQL MySQL SQLite
Int INTEGER INTEGER INTEGER
BigInt BIGINT BIGINT BIGINT
Float DOUBLE PRECISION DOUBLE DOUBLE
Decimal DECIMAL(10,2) DECIMAL(10,2) DECIMAL(10,2)

Example Prisma Schema

model Product {
  id          Int     @id @default(autoincrement())
  quantity    Int     @default(0)
  viewCount   BigInt  @default(0)
  weight      Float?
  price       Decimal
  rating      Float   @default(0.0)

  @@map("products")
}

Generated SQL (PostgreSQL)

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

When to Use Each Type

  • Int: Standard integers up to ~2.1 billion. Use for IDs, counts, ages, quantities.
  • BigInt: Large integers beyond Int range. Use for timestamps in milliseconds, large counters, snowflake IDs.
  • Float: Double-precision floating point. Use for scientific calculations, coordinates, ratings where exact precision isn't critical.
  • Decimal: Fixed-point decimal with exact precision. Use for monetary values, prices, financial calculations where rounding errors are unacceptable.

Autoincrement with BigInt

When BigInt is used with @default(autoincrement()), PostgreSQL generates BIGSERIAL instead of SERIAL:

model Event {
  id BigInt @id @default(autoincrement())
}

Produces id BIGSERIAL PRIMARY KEY in PostgreSQL.

Use Case

You are building an e-commerce system where product prices must use DECIMAL for exact monetary calculations, while view counts need BIGINT to handle potentially billions of page views across popular products.

Try It — Prisma to SQL Schema

Open full tool