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

jsonb column cannot get default value #1330

Closed
devvit opened this issue Mar 25, 2017 · 1 comment
Closed

jsonb column cannot get default value #1330

devvit opened this issue Mar 25, 2017 · 1 comment

Comments

@devvit
Copy link

devvit commented Mar 25, 2017

pg table like this, photos columns with default value

pg table

code

DB = Sequel.connect(adapter: 'postgres', database: 'town_dev')
DB.extension :pg_json

Sequel::Model.plugin :defaults_setter

class Post < Sequel::Model

end

output

output

column score(int type) work well, except photos column

@jeremyevans
Copy link
Owner

Parsing arbitrary default values is not something that Sequel can do, because it requires a full SQL parser specific to the database, and Sequel does not parse SQL. It's possible that this particular case could be handled, but it invites the slippery slope, since everyone will want custom parsers for their specific case. That's not a path I want to go down.

The default_values plugin already has support for setting the default value manually for specific columns, you should use that:

Post.default_values[:photos] = lambda{Sequel.pg_jsonb('hello'=>'world')}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants