Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Drizzle ORM · Function

real

real() declares a PostgreSQL single-precision floating-point column in a Drizzle schema. PostgreSQL also names this type float4.

How it works

In Drizzle’s PostgreSQL schema API, call real() inside a pgTable definition to create a single-precision floating-point column. The column can also receive a default value, including a SQL expression when the default needs an explicit PostgreSQL cast.

Syntax

real()

Returns

A Drizzle PostgreSQL column builder representing the database real type.

Key points

  • The type is intended for four-byte, single-precision floating-point values.
  • A literal numeric default can be attached by chaining .default(...) to real().
  • A SQL default expression can explicitly cast a value to PostgreSQL real.

Common mistakes

  • real stores a single-precision floating-point value and occupies 4 bytes.

Example: Declare a PostgreSQL real column

import { real, pgTable } from "drizzle-orm/pg-core";

export const measurements = pgTable("measurements", {
  value: real(),
});

Defines a PostgreSQL table with a single-precision floating-point column.

When to use it

Store single-precision measurements

A measurement or sensor table needs compact floating-point storage.

Model PostgreSQL real columns

A schema requires PostgreSQL's native real/float4 type.

Define a default value

A column needs a numeric database default.

Interview questions

QHow do you declare a PostgreSQL real column in Drizzle?

Use real() from drizzle-orm/pg-core as a column builder inside pgTable. It maps to PostgreSQL’s real type, also known as float4.

Follow-up: How would you define a database default? Use .default(10.10), or provide a SQL expression such as sql'10.10'::real when an explicit cast is needed.

QWhat database type and precision does real() represent?

The generated PostgreSQL type is real, and the documentation identifies it as float4. It represents a four-byte, single-precision floating-point number.

Follow-up: What trade-off follows from single precision? It uses less storage than higher-precision numeric types but cannot represent values with the same precision.

QWhere does real() belong in a Drizzle schema?

Import real from drizzle-orm/pg-core and place real() in the object passed to pgTable. This produces a typed schema declaration that Drizzle can use for migrations and queries.

Follow-up: How can the declaration be customized? Chain supported column methods, such as .default(...), on the builder before placing it in the table definition.

  • float4
  • pgTable
  • sql
  • default

Source: PostgreSQL column types - Drizzle ORM. Checked 2026-10-16.