Error when fetching data from database view

The error I am getting when I am trying to fetch data from database view is
NeonDbError: invalid input syntax for type integer: "NaN"

The schema of database and view is
export const clients = pgTable("clients", {
  id: integer().primaryKey().generatedAlwaysAsIdentity(),
  name: varchar({ length: 30 }).notNull(),
  email: varchar({ length: 30 }).notNull(),
  phone: varchar({length: 15}).notNull(),
  clientType: varchar("client_type", {enum: ["business", "individual"]}).notNull(),
  address: varchar().notNull(),
  status: varchar({ enum: ["active", "inactive"] }).notNull(),
  notes: varchar({length: 256})
});

export const clientRelations = relations(clients, ({ many }) => ({
  invoices: many(invoices),
}));

export const clientStatsViews = pgView("client_stats").as(
  (qb) => qb.select({
    totalCount: sql<number>`cast(count(*) as int)`.as("total_clients"),
    inactiveCount: sql<number>`cast(count(${clients.id}) filter (where ${clients.status} = 'inactive') as int)`.as("inactive_clients"),
    activeCount: sql<number>`cast(count(${clients.id}) filter (where ${clients.status} = 'active') as int)`.as("active_clients"),
  }).from(clients)
)
image.png
Was this page helpful?