Is this a bug with arrays?
In postgres I have a column defined like this:
For insertions, drizzle says I don't need to define
someArrayField
since it has a default. Yet when I try to insert a record, I get this error:
Am I doing this incorrectly? interestingly, on localhost, this has no issues when I use import { drizzle } from 'drizzle-orm/postgres-js';
This only has issues when deployed when I use import { drizzle } from 'drizzle-orm/neon-serverless';
I wanted to just do .default([])
but then drizzle kit tells me:
17 Replies
Can you try changing the the column to:
The question I'd have is, did you run push/migrate after you defined the the default?
when i defined it like this, yes i pushed it
$default([])
doesnt work
using .$default(() => [])
in my code seems to work
well, once a record exists in the db, if i try to change from ARRAY[]::text[]
to () => []
it says
My bad, this is the correct code
You don't have to run migrations for this. The $default function run purely in js
Also, you might have better luck with the following syntax. See here https://stackoverflow.com/questions/30933266/empty-array-as-postgresql-array-column-default-value
Stack Overflow
Empty array as PostgreSQL array column default value
I have a defined an array field in postgresql 9.4 database:
character varying(64)[]
Can I have an empty array e.g. {} for default value of that field?
What will be the syntax for setting so?
I'm
this syntax works
why wouldnt the original
ARRAY[]::text[]
work?No idea
seems like two:
1.
ARRAY[]
stynax default doesnt work for neon (probably a bug in neon?)
2. drizzle does not handle default arrays properly:
.default([])
yeilds:
The
default()
is designed to receive sql. Although unfortunately the interfaces doesn't convey that.GitHub
[BUG]: .default() method accepts Date object but should only accept...
What version of drizzle-orm are you using? 0.29.1 What version of drizzle-kit are you using? 0.20.6 Describe the Bug This relates to #1105 (comment). When using an integer column in timestamp mode,...
weird, seems like
[]
is neither SQL<unknown> or DateIt's definitely not. But it's the same bug.
for me, the interface is
SQL<unknown> | string[]
(why it doesnt throw an error for me)Yes, what I'm trying to say is that the interface is not correct. If you are using a Date or an array, drizzle is showing you the wrong interface for the
.default()
methodoh, nvm, its based on the column type. understood