Casting column to enum type

Hi all, I create a schema like this:
export const typeEnum = taxSchema.enum("type", Object.values(OrderType) as any as [string, ...string[]]);
export const statusEnum = taxSchema.enum("status", Object.values(OrderStatus) as any as [string, ...string[]]);
export const currencyPairEnum = taxSchema.enum(
"currencyPair",
Object.values(CurrencyPair) as any as [string, ...string[]],
);
export const orders = taxSchema.table("orders", {
id: varchar("id").primaryKey(),
type: typeEnum("type"),...
export const typeEnum = taxSchema.enum("type", Object.values(OrderType) as any as [string, ...string[]]);
export const statusEnum = taxSchema.enum("status", Object.values(OrderStatus) as any as [string, ...string[]]);
export const currencyPairEnum = taxSchema.enum(
"currencyPair",
Object.values(CurrencyPair) as any as [string, ...string[]],
);
export const orders = taxSchema.table("orders", {
id: varchar("id").primaryKey(),
type: typeEnum("type"),...
However, when i run
const db = drizzle(new RDSDataClient({}), {
secretArn: process.env.RDS_SECRET_ARN!,
resourceArn: process.env.RDS_CLUSTER_ARN!,
database: 'taxservice'
});
return db.insert(orders).values(data);
const db = drizzle(new RDSDataClient({}), {
secretArn: process.env.RDS_SECRET_ARN!,
resourceArn: process.env.RDS_CLUSTER_ARN!,
database: 'taxservice'
});
return db.insert(orders).values(data);
I get the following error:
Error: ERROR: column "type" is of type type but expression is of type character varying
Hint: You will need to rewrite or cast the expression.
Position: 782; SQLState: 42804
Error: ERROR: column "type" is of type type but expression is of type character varying
Hint: You will need to rewrite or cast the expression.
Position: 782; SQLState: 42804
Why is this happening? Shouldn't drizzle manage the casting for me? The value for type being passed in is just a string, but I feel like this should be mapped automatically, correct?
3 Replies
PGeyer
PGeyerOP7mo ago
GitHub
GitHub - patrick-geyer-21/drizzle-bug
Contribute to patrick-geyer-21/drizzle-bug development by creating an account on GitHub.
PGeyer
PGeyerOP7mo ago
I have created the repo for the potential bug here @Andrew Sherman maybe you could take a look? @Turso I can offer a bounty on this if someone can tell me the solution.
Angel
Angel7mo ago
Not sure if it is related, But it could be: https://discord.com/channels/1043890932593987624/1120919676457848946/1120919676457848946 For myself i stop using pgEnum with AWS Data API, and use just text strings and control the enums in my code validation. If anyone has been able to solve that, can just post how?
Want results from more Discord servers?
Add your server