Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Not properly handling default value on column of type _jsonb, an array of jsonb in postgres. #2861

Closed
brandon-lavigne-tfs opened this issue Aug 27, 2024 · 3 comments · May be fixed by #3782
Labels
bug Something isn't working

Comments

@brandon-lavigne-tfs
Copy link

What version of drizzle-orm are you using?

0.33.0

What version of drizzle-kit are you using?

^0.24.2

Describe the Bug

Not properly handling default value on column of type _jsonb, an array of jsonb in postgres.

CREATE TABLE public.deleteme (
	column1 json DEFAULT '{}'::json NOT NULL,
	column2 jsonb DEFAULT '[]'::jsonb NOT NULL,
	column3 _jsonb DEFAULT ARRAY[]::jsonb[] NOT NULL
);
Screenshot 2024-08-27 at 11 33 38 AM
drizzle-kit pull
SyntaxError: Unexpected token 'R', "RAY" is not valid JSON
    at JSON.parse (<anonymous>)
    at /Users/brandon.lavigne/git/example/packages/orm/node_modules/drizzle-kit/bin.cjs:19353:66
    at Array.map (<anonymous>)
    at defaultForColumn (/Users/brandon.lavigne/git/example/packages/orm/node_modules/drizzle-kit/bin.cjs:19342:74)
    at /Users/brandon.lavigne/git/example/packages/orm/node_modules/drizzle-kit/bin.cjs:19111:36
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Expected behavior

Instrospection to set the default sql value explicitly. Something like:

column3: jsonb('column3').array().default(sql`ARRAY[]::jsonb[]`),

Environment & setup

local macos

@L-Mario564
Copy link
Collaborator

This seems to be an issue with how you declared the default value. Try this instead:

column3: jsonb('column3').array().default(sql`'{}'::jsonb[]`),

@dmarkow
Copy link

dmarkow commented Nov 4, 2024

@L-Mario564 Getting the same issue, using a database that was set up before trying out drizzle. I'd like to use pull to introspect the database but if fails at the default.

My default value in for one of my columns is ARRAY['{"type": "paragraph", "children": [{"text": ""}]}'::jsonb]. I'm not sure it's possible to write this default using curly brace notation instead of ARRAY[] notation. Using ARRAY[...] is a typical way that default array values will be set in a database, so it would be great if drizzle supported this.

@elie222
Copy link

elie222 commented Dec 2, 2024

@L-Mario564 Getting the same issue, using a database that was set up before trying out drizzle. I'd like to use pull to introspect the database but if fails at the default.

My default value in for one of my columns is ARRAY['{"type": "paragraph", "children": [{"text": ""}]}'::jsonb]. I'm not sure it's possible to write this default using curly brace notation instead of ARRAY[] notation. Using ARRAY[...] is a typical way that default array values will be set in a database, so it would be great if drizzle supported this.

Same issue here. Facing this on an existing db. Did you find a quick fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants