DT
Drizzle Team•2y ago
volks

Postgres's Serial column type doesn't automatically have a default

Hello, when using postgres's serial types, and setting them as primary keys, there is an issue currently that does not mark them as has default. What I mean is, from the docs The data types smallserial, serial and bigserial are not true types, but merely a notational convenience for creating unique identifier columns (similar to the AUTO_INCREMENT property supported by some other databases), the Serial types already have a default implementation, but if you use them as is in Drizzle, they aren't regarded as having a default
type NewTest = InferModel<typeof test, 'insert'>;
^? type NewTest = {
id: number; <-- Should be nullable
}

export const test = pgTable("test", {
id: smallserial('id').primaryKey(),
});
type NewTest = InferModel<typeof test, 'insert'>;
^? type NewTest = {
id: number; <-- Should be nullable
}

export const test = pgTable("test", {
id: smallserial('id').primaryKey(),
});
I'd expect it to be nullable for inserts as serials have default
5 Replies
Dan
Dan•2y ago
Looks like a bug, could you create an issue on GH please?
volks
volksOP•2y ago
GitHub
[BUG]: Serial type in PostgreSQL not recognized as having a default...
What version of drizzle-orm are you using? 0.26.1 What version of drizzle-kit are you using? 0.18.1 Describe the Bug I have encountered an issue with handling PostgreSQL's serial types (smallse...
Antebios
Antebios•2y ago
Thank you! I thought I was going crazy, but I have the same issue.
kstc23boi
kstc23boi•2y ago
+1 here
kstc23boi
kstc23boi•2y ago
GitHub
PostgreSQL: add generated always as identity as modern alternativ...
It's basically the newer (and recommended) way to make auto incrementing columns. Example: create table old_way (id serial primary key); create table new_way (id integer primary key generated a...
GitHub
Support generated columns · Issue #261 · drizzle-team/drizzle-orm
CREATE TABLE t1( a INTEGER PRIMARY KEY, b INT, c TEXT, d INT GENERATED ALWAYS AS (a*abs(b)) VIRTUAL, e TEXT GENERATED ALWAYS AS (substr(c,b,b+1)) STORED );
Want results from more Discord servers?
Add your server