-
Notifications
You must be signed in to change notification settings - Fork 137
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
Support for function-based DEFAULT values, not only literals #36
Comments
Off the top of my head, we'll probably need to add a Func class that marks the default value as a function instead of a literal value. So you would use it like this: |
Is this issue still in progress? event_time = fields.DateTimeField()
event_date = fields.DateField(default="toDate(event_time)") With above i get error |
Yes, I'm actively working on this for v2. For the use case you described, try using "materialized" instead of "default". It should work, and would also prevent the event_date and event_time from being mismatched (since event_date will always be calculated from event_time, you won't be able to override its value by mistake). |
Yes, i thought about materialized field. It may help. But will be waiting for upgraded "default" option feature =) |
While working on this feature I ran into a showstopper that probably makes it impossible to support functions as default values. Consider the
This generates an SQL statement more or less like this:
and then the field values are sent as tab-separated strings:
The |
I saw this feature in one php project, which written with Symfony and uses Annotations (if you know these things). Look at the code: /**
* @var string
* @CHType(type="Date DEFAULT toDate(today())", behavior="SKIP_PROPERTY")
*/
protected $date = self::DATE_DEFAULT; It describes one calculated field of a table. If we divide a params into a two parts and translate it into python, we could write like this: date = fields.DateField(default='toDate(today())', skip_property=True) And then we should check this param, and if property 'skip_property' equal 'True', then remove it from INSERT statement. |
@VeryaskinMax - the problem is not identifying that there's a default value, its generating the correct INSERT statement. If you are inserting two records, one with a default value and one without, you need two separate INSERT statements (since the list of fields to insert is different between the two records). |
@ishirav, maybe I'm wrong, but if in the Model in the property (e.g. |
I'm not sure I understand what you're saying, but I think you're mixing between DEFAULT and MATERIALIZED.
|
Have exactly same problem: CREATE TABLE content
(
dt DateTime,
date Date default toDate(dt)
)
ENGINE = MergeTree()
PARTITION BY toYYYYMM(date)
ORDER BY (date) Model definition: from infi.clickhouse_orm import fields, models, engines, migrations
class ClickhouseModel(models.Model):
dt = fields.DateTimeField()
date = fields.DateField(default='toDate(dt)')
engine = engines.MergeTree(partition_key=('toYYYYMM(dt)',), order_by=('date',)) On migrate:
|
Available in v2.0.0 |
I'd like to create this simple table:
so I use the following:
and get the error:
Even if I changed to this
I still get the error (due to quoting):
How can I achieve the desired behaviour?
The text was updated successfully, but these errors were encountered: