© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
4 replies
nightire

define a jsonb column with `{}` as default value does not work

I'm trying to define a jsonb column with default value like this:

  attrs: pg
    .jsonb('attrs')
    .$type<Record<string, JSONValue>>()
    .default(sql`'{}'::jsonb`),
  attrs: pg
    .jsonb('attrs')
    .$type<Record<string, JSONValue>>()
    .default(sql`'{}'::jsonb`),


however, the inferred type definition of
attrs
attrs
still be
Record<string, JSONValue> | null
Record<string, JSONValue> | null
. How to get rid of the
null
null
?
Solution
attrs: pg
    .jsonb('attrs')
    .$type<Record<string, JSONValue>>()
    .default(sql`'{}'::jsonb`).notNull(),
attrs: pg
    .jsonb('attrs')
    .$type<Record<string, JSONValue>>()
    .default(sql`'{}'::jsonb`).notNull(),
Jump to solution
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

define default value for array
Drizzle TeamDTDrizzle Team / help
3y ago
help with drizzle-zod with jsonb column
Drizzle TeamDTDrizzle Team / help
3y ago
SQLite Timestamp does not allow a default NULL value
Drizzle TeamDTDrizzle Team / help
2y ago
How to define types for jsonb
Drizzle TeamDTDrizzle Team / help
3y ago