-
Notifications
You must be signed in to change notification settings - Fork 100
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
[sqlalchemy] [Feature Request] Support default values #324
Comments
try to use
|
Thanks to this thread I ws able to find out the magic syntax: CREATE TABLE test.`ModelMetadata` (
pkid BIGINT GENERATED ALWAYS AS IDENTITY,
name STRING NOT NULL,
version STRING NOT NULL,
insert_timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
PRIMARY KEY (pkid)
) USING DELTA
TBLPROPERTIES(
'delta.minReaderVersion' = '1',
'delta.minWriterVersion'='7',
'delta.feature.allowColumnDefaults' = 'enabled'
); ...but I don't really know how to integrate that with If that is required for defaults then I guess this projects needs to implement a custom compiler to add the required |
With CREATE TABLE test.`ModelMetadata` (
pkid BIGINT GENERATED ALWAYS AS IDENTITY,
name STRING NOT NULL,
version STRING NOT NULL,
insert_timestamp TIMESTAMP DEFAULT now() NOT NULL,
PRIMARY KEY (pkid)
) USING DELTA; ...which gives the below error:
|
Or, even better, just enable |
In my specific case it appears I can hack around it with: @event.listens_for(Base.metadata, "after_create")
def set_default_insert_timestamp(target, connection, **kw):
for table in target.tables:
connection.execute(DDL(f"""
ALTER TABLE {table} SET TBLPROPERTIES(
'delta.feature.allowColumnDefaults' = 'enabled'
);
"""))
connection.execute(DDL(f"""
ALTER TABLE {table}
ALTER COLUMN insert_timestamp
SET DEFAULT CURRENT_TIMESTAMP;
""")) ...but that's a bit gross 🤢 It would be nice for the standard |
Hey folks thanks for the write-up and debugging! I'm pleased to see that you worked out how to hack this together using @dhirschfeld would you shoot an email to |
It appears that default values aren't supported?
databricks-sql-python/src/databricks/sqlalchemy/base.py
Line 64 in 3f6834c
Trying to create a schema with the below
server_default
gives a spark error:Edit:
It looks like the internal error is created by having a
TIMESTAMP_NTZ
type with theCURRENT_TIMESTAMP
default. Using the correctTIMESTAMP
type for the column then gives the table feature was not enabled error.To work around the latter error requires setting the table properties, which AFAICS can't be done from
sqlalchemy
, at least not directly.The text was updated successfully, but these errors were encountered: