© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
1 reply
Baron Von Enablestein

pgEnum conversion not working as expected

I have the following pgEnum defined:

export const ApprovalRequestTypePgEnum = pgEnum('approval_request_type', ['CREDIT_NOTE']);
export const ApprovalRequestTypePgEnum = pgEnum('approval_request_type', ['CREDIT_NOTE']);

(Yes, there'll be more types later). My schema is:

export const approvalRequestsTable = pgTable('approval_requests', {
  id: uuid('id').default(sql`gen_random_uuid()`).primaryKey().notNull(),
  requestorId: integer('requestor_id').notNull().references(() => employeesTable.workerId),
  type: ApprovalRequestTypePgEnum('type').notNull(),
  approvalObjectId: uuid('approval_object_id').notNull(),
  status: ApprovalStatusPgEnum('status').notNull(),
  totalValue: integer('total_value').notNull(),
  currencyCode: text('currency_code').notNull(),
});
export const approvalRequestsTable = pgTable('approval_requests', {
  id: uuid('id').default(sql`gen_random_uuid()`).primaryKey().notNull(),
  requestorId: integer('requestor_id').notNull().references(() => employeesTable.workerId),
  type: ApprovalRequestTypePgEnum('type').notNull(),
  approvalObjectId: uuid('approval_object_id').notNull(),
  status: ApprovalStatusPgEnum('status').notNull(),
  totalValue: integer('total_value').notNull(),
  currencyCode: text('currency_code').notNull(),
});


However when I do:

export const insertApprovalRequest = async (approvalRequest: ApprovalRequestInput): Promise<ApprovalRequest> => {
  logger.info('Inserting approval request', { approvalRequest });
  const insertedApprovalRequest = await db
    .insert(approvalRequestsTable).values({
      ...approvalRequest,
      type: ApprovalRequestType.CREDIT_NOTE
    }).returning().then((res) => res[0]);
  logger.info('Inserted approval request', { insertedApprovalRequest });

  return getApprovalRequest(insertedApprovalRequest.id) as Promise<ApprovalRequest>;
};
export const insertApprovalRequest = async (approvalRequest: ApprovalRequestInput): Promise<ApprovalRequest> => {
  logger.info('Inserting approval request', { approvalRequest });
  const insertedApprovalRequest = await db
    .insert(approvalRequestsTable).values({
      ...approvalRequest,
      type: ApprovalRequestType.CREDIT_NOTE
    }).returning().then((res) => res[0]);
  logger.info('Inserted approval request', { insertedApprovalRequest });

  return getApprovalRequest(insertedApprovalRequest.id) as Promise<ApprovalRequest>;
};


I get the error
ERROR: column \"type\" is of type approval_request_type but expression is of type text; Hint: You will need to rewrite or cast the expression.
ERROR: column \"type\" is of type approval_request_type but expression is of type text; Hint: You will need to rewrite or cast the expression.


How can I solve this? My ApprovalRequestType enum is also mapped to
'CREDIT_NOTE'
'CREDIT_NOTE'
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

schemaFilter not working as expected
Drizzle TeamDTDrizzle Team / help
14mo ago
inArray not working as expected
Drizzle TeamDTDrizzle Team / help
16mo ago
Drizzle-kit not working as expected
Drizzle TeamDTDrizzle Team / help
16mo ago
DrizzleKit "tablesFilter" not working as expected
Drizzle TeamDTDrizzle Team / help
2y ago