Skip to content
Aurabase Logo
aurabase

Choose column types

Choose the type of each column from what you will store and query, declare it with the CLI or SQL, and know how the SDK and the REST API return it, including where precision can be lost.

How-to guide9 min readLevel beginner

Columns of an Aurabase table are PostgreSQL 18 columns: any built-in type works, plus the types of the extensions every project has installed (vector, citext, hstore, ltree). What changes the choice in practice is how the value travels as JSON to your application. This page picks a type per use, declares them, and shows what the SDK receives.

Prerequisites#

  • A linked project: aura link <project-id>.

  • The example schema, installed with the service role key of the project:

    export AURABASE_SERVICE_ROLE_KEY=aura_sk_…
    aura db seed --example docs

    It creates profiles, orgs, org_members, posts, todos, the view open_todos and the function todo_count(p_user uuid). See Example schema.

The examples create the enum sch_types_status and the table sch_types_items, then remove them.

Choose a type#

You storeUseAvoid, and why
Names, titles, free texttextvarchar(n): no faster than text; add a check (char_length(col) <= n) if you need a limit.
Text compared without case (emails, usernames)citextlower() everywhere in queries.
Counters, quantitiesint (up to 2,147,483,647) or bigintfloat for counts.
Money, pricesnumeric(12,2)float or double precision: 0.1 + 0.2 is not 0.3. money depends on the locale settings.
Measures, scoresdouble precisionnumeric when exactness does not matter: slower.
A moment in timetimestamptztimestamp: it has no time zone, so two servers may read it differently.
A calendar day, a time of day, a durationdate, time, intervalText dates.
Yes or nobooleanint flags.
Row idsbigint generated always as identity or uuid default gen_random_uuid()serial (older form of identity).
A fixed list of statesAn enum, or text with a checkFree text with no check.
A small list of valuestext[], int[]A join table, when you need to query or constrain each element.
Documents with a loose shapejsonbjson: kept as typed, not indexable with GIN, slower to query.
Embeddings for semantic searchvector(<dimension>)float[]: no distance operators, no vector index.
FilesAurabase Storage, with the path in a text columnbytea for large files.
Full-text searchtsvectorlike '%…%' on large tables.
Tree paths, key/value pairs, IP addressesltree, hstore, inetText you parse yourself.

uuid-ossp and pgcrypto are installed too, but gen_random_uuid() is built into PostgreSQL and needs neither. The list of installed extensions is on Extensions.

CLI and API type names#

aura db table create and the schema API use short names. Each maps to one PostgreSQL type:

CLI and APIPostgreSQLCLI and APIPostgreSQL
texttexttimestamptztimestamp with time zone
intintegertimestamptimestamp without time zone
bigintbigintdate, timedate, time
floatdouble precisionjson, jsonbjson, jsonb
numericnumeric (no precision)bytea, tsvectorbytea, tsvector
boolbooleanarray(<type>) or <type>[]<type>[]
uuiduuidvector(<n>)vector(<n>)
enum(<name>)The enum type <name>, which must exist

The schema API also accepts inet, interval and money. Anything else (numeric(12,2), citext, ltree, int4range, a domain) is created in SQL with aura db raw.

Create a table with every family#

create type sch_types_status as enum ('draft', 'published', 'archived');

create table sch_types_items (
  id bigint generated always as identity primary key,
  name text not null,
  email citext,
  price numeric(10,2),
  big_amount numeric,
  quantity int,
  views bigint,
  ratio double precision,
  in_stock boolean not null default true,
  status sch_types_status not null default 'draft',
  tags text[] not null default '{}',
  attributes jsonb not null default '{}',
  published_at timestamptz,
  local_time timestamp,
  due_on date,
  duration interval,
  embedding vector(3),
  raw_bytes bytea
);

insert into sch_types_items (name, email, price, big_amount, quantity, views, ratio, status, tags,
  attributes, published_at, local_time, due_on, duration, embedding, raw_bytes)
values ('Lamp', 'Ada@Example.com', 19.90, 12345678901234567890.123, 3, 9007199254740993, 0.1,
  'published', '{home,light}', '{"color": "black", "watts": 40}', '2026-11-21 10:00:00+01',
  '2026-11-21 10:00:00', '2026-12-01', '1 day 2 hours', '[0.1,0.2,0.3]', '\x6869');
  ℹ No results (0 rows).

How values come back in the SDK#

The SDK and the REST API return rows as JSON, and JavaScript parses JSON numbers as 64-bit floats. Read the row back:

import { createClient } from '@aurabase/aurabase-js'

const admin = createClient(process.env.AURABASE_URL!, process.env.AURABASE_SERVICE_ROLE_KEY!)

const { data, error } = await admin.db.from('sch_types_items').select('*').single()
if (error) throw error
for (const [column, value] of Object.entries(data as Record<string, unknown>)) {
  console.log(column.padEnd(12), typeof value, JSON.stringify(value))
}
id           number 1
name         string "Lamp"
email        string "Ada@Example.com"
price        number 19.9
big_amount   number 12345678901234567000
quantity     number 3
views        number 9007199254740992
ratio        number 0.1
in_stock     boolean true
status       string "published"
tags         object ["home","light"]
attributes   object {"color":"black","watts":40}
published_at string "2026-11-21T09:00:00+00:00"
local_time   string "2026-11-21T10:00:00"
due_on       string "2026-12-01"
duration     string "1 day 02:00:00"
embedding    string "[0.1,0.2,0.3]"
raw_bytes    string "\\x6869"

What to read from this output:

  • numeric and bigint arrive as JSON numbers. price lost its trailing zero (19.9), big_amount lost its last digits and views (253 + 1) became 9007199254740992. Any integer above 9,007,199,254,740,991 and any decimal with more than about 15 significant digits is rounded by JSON.parse. See the next section.
  • timestamptz comes back with a +00:00 offset (ISO 8601, UTC), whatever offset was written: 10:00:00+01 was returned as 09:00:00+00:00. Sessions of the REST API run with the time zone Etc/UTC. timestamp comes back exactly as stored, without an offset. Convert to the user's time zone in your application.
  • interval uses the PostgreSQL text form (1 day 02:00:00), not ISO 8601.
  • vector arrives as a string ("[0.1,0.2,0.3]"): parse it with JSON.parse before using the numbers.
  • bytea arrives as a hex string (\x6869), which is why large binary data belongs in Storage.
  • Arrays and jsonb arrive as JSON arrays and objects, ready to use.
  • citext keeps the case you wrote (Ada@Example.com) and compares without it.

Keep big numbers exact#

Cast the column to text in the select list, and convert it in your code with a decimal or BigInt library:

import { createClient } from '@aurabase/aurabase-js'

const admin = createClient(process.env.AURABASE_URL!, process.env.AURABASE_SERVICE_ROLE_KEY!)

const { data, error } = await admin.db.from('sch_types_items').select('price::text, big_amount::text, views::text').single()
console.log(data, error)
console.log(BigInt((data as { views: string }).views) + 1n)
{
  price: '19.90',
  big_amount: '12345678901234567890.123',
  views: '9007199254740993'
} null
9007199254740994n

An id generated by bigint generated always as identity stays far below 253 in practice; the risk is with values imported from elsewhere (snowflake ids, amounts in the smallest currency unit of a large total).

Enums#

An enum is a type with a fixed, ordered list of labels. Create it in SQL, then use it in SQL or with the CLI (aura db table create orders "status:enum(order_status)"). A value outside the list is refused before the row is written:

import { createClient } from '@aurabase/aurabase-js'

const admin = createClient(process.env.AURABASE_URL!, process.env.AURABASE_SERVICE_ROLE_KEY!)

const bad = await admin.db.from('sch_types_items').insert({ name: 'Desk', status: 'deleted' })
console.log(bad.error?.status, bad.error?.code, bad.error?.message)
400 INVALID_INPUT invalid input value for enum sch_types_status: "deleted"

Add a label with alter type. PostgreSQL does not let a new label be used in the transaction that adds it, and each aura db raw call is one transaction, so add it in one call and use it in the next:

aura db raw "alter type sch_types_status add value 'deleted' after 'archived'"
aura db raw "insert into sch_types_items (name, status) values ('Desk', 'deleted') returning name, status"
  ℹ No results (0 rows).
  name │ status
  ─────┼────────
  Desk │ deleted

  ℹ 1 row(s).

A label cannot be removed or renamed in place by a simple statement (alter type … rename value renames, removing needs a new type). When the list changes often, prefer text with a check constraint, which you can replace in one statement. GET /v1/db/{project_id}/schema returns each enum with its labels in order (Read and export your schema).

JSON and JSONB#

Use jsonb: PostgreSQL stores it parsed, so it can be indexed and queried with ->, ->> and @>. json keeps the text as written (key order, duplicates) and only makes sense to store a payload byte for byte. Filter on a key from the SDK with contains:

import { createClient } from '@aurabase/aurabase-js'

const admin = createClient(process.env.AURABASE_URL!, process.env.AURABASE_SERVICE_ROLE_KEY!)

const lamps = await admin.db
  .from('sch_types_items')
  .select('name, attributes->>color')
  .contains('attributes', { color: 'black' })
  .contains('tags', ['home'])
console.log(lamps.data, lamps.error)
[ { name: 'Lamp', color: 'black' } ] null

To make such filters fast on a large table, add a GIN index: Indexes.

Vectors#

vector comes from pgvector, installed in every project at creation. Declare the dimension of your embedding model (vector(1536)), then order by distance: <-> is the Euclidean distance, <=> the cosine distance, <#> the negative inner product.

aura db raw "select name, round((embedding <-> '[0.1,0.2,0.4]')::numeric, 3) as distance from sch_types_items where embedding is not null order by embedding <-> '[0.1,0.2,0.4]' limit 5"
  distance │ name
  ─────────┼─────
  0.1      │ Lamp

  ℹ 1 row(s).

A vector of another length is refused with expected 3 dimensions, not 2. For similarity search on many rows, add an hnsw or ivfflat index (Indexes).

Result#

The table holds two rows; one enum label was added:

aura db raw "select name, status, price from sch_types_items order by id"
  name │ price │ status
  ─────┼───────┼──────────
  Lamp │ 19.9  │ published
  Desk │ NULL  │ deleted

  ℹ 2 row(s).

Common errors#

MessageCauseFix
400 INVALID_INPUT invalid input value for enum sch_types_status: "deleted" (SQLSTATE 22P02)A label that is not in the enum.Send one of the labels, or add it with alter type … add value.
400 INVALID_INPUT invalid input syntax for type bigint: "abc"Text sent to a numeric column, or a filter on an id with a non-number.Send a number; check the filter value.
400 NUMERIC_OUT_OF_RANGE (SQLSTATE 22003)A value larger than the column allows (int above 2,147,483,647, numeric(10,2) above 99,999,999.99).Use bigint or a wider numeric.
unsafe use of new value "deleted" of enum type sch_types_status (…) Hint: New enum values must be committed before they can be used.The new label is used in the transaction that added it.Add the label in one request, use it in the next.
expected 3 dimensions, not 2A vector of the wrong length.Use the dimension declared on the column.
A large number differs by a few units in your appJSON.parse rounded a bigint or numeric.Select it as col::text.

Clean up#

Drop the table first, then the enum type it used:

drop table sch_types_items;
drop type sch_types_status;
  ℹ No results (0 rows).

See also#

@aurabase/aurabase-js@0.7.5 · aura@0.3.4↗ Report a problem