© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
8 replies
bluesky

Creating composite types in PostgreSQL

Hi, I'm curious how I could recreate the following code using drizzle.
-- composite type
CREATE TYPE author AS (
    name text,
    role text
);

CREATE TABLE books (
    book_id serial PRIMARY KEY,
    title text,
    authors author[]
);
-- composite type
CREATE TYPE author AS (
    name text,
    role text
);

CREATE TABLE books (
    book_id serial PRIMARY KEY,
    title text,
    authors author[]
);


Is it simply
type Author = {
    name: string;
    role: string;
};

const books = pgTable('books', {
    bookId: serial('book_id').primaryKey(),
    title: text('title'),
    authors: text('authors').array().$type<Author>(),
});
type Author = {
    name: string;
    role: string;
};

const books = pgTable('books', {
    bookId: serial('book_id').primaryKey(),
    title: text('title'),
    authors: text('authors').array().$type<Author>(),
});


Because I ran
\dT
\dT
and it didn't show a custom type for the Author in postgres
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

creating external types based on drizzle types
Drizzle TeamDTDrizzle Team / help
3y ago
Composite PK
Drizzle TeamDTDrizzle Team / help
2y ago
Composite Primary Key?
Drizzle TeamDTDrizzle Team / help
16mo ago
create custom types in postgresql and still have type support using drizzle orm
Drizzle TeamDTDrizzle Team / help
2y ago