I am getting an error when entering an id with a uuid value
const uuid = uuidv4()
await db
.withSchema("schema_name")
.insertInto("table_name")
.values({
id: uuid
})
.execute();
Error: ERROR: column "id" is of type uuid but expression is of type character varying
Hint: You will need to rewrite or cast the expression.
Solution:Jump to solution
Hey 👋
You should try casting it to
uuid
using sql
template tag:
```ts...4 Replies
Solution
Hey 👋
You should try casting it to
uuid
using sql
template tag:
wow, thanks, it's worked!
If you have the option, I'd suggest using
TEXT
instead of UUID
as the data type in the DB. In my experience, the UUID
data type causes more trouble than it's worth
With TEXT
you use 36 bytes per uuid value as with UUID
you only use 16. But that's pretty much the only benefit of using UUID
nowadays. And disk space is cheap.I found it very difficult to work with him, thanks for the help!