© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
2 replies
Zeraph

Why fields with default value is nullable

Consider this schema:
export const blogMetadata = pgTable('blog_metadata', {
  id: varchar('id').primaryKey(),
  view: integer('view').default(0),
});
export const blogMetadata = pgTable('blog_metadata', {
  id: varchar('id').primaryKey(),
  view: integer('view').default(0),
});


When I do a query:
db.select().from(blogMetadata).where(eq(blogMetadata.id, id))
db.select().from(blogMetadata).where(eq(blogMetadata.id, id))


The resultant type is:
{
  id: string;
  view: number | null
}
{
  id: string;
  view: number | null
}


Why is
view
view
nullable in this case? It should always be an integer due to the default value of 0, isn't it? Or am I missing something?
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

TypeError for nullable/optional fields
Drizzle TeamDTDrizzle Team / help
11mo ago
rqb v2: `with` is always nullable
Drizzle TeamDTDrizzle Team / help
9mo ago
Is it possible to generate a default value concatenating with NEXTVAL?
Drizzle TeamDTDrizzle Team / help
16mo ago
Cannot update / insert default value
Drizzle TeamDTDrizzle Team / help
17mo ago