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

SQLAlchemy/DDL: Support server_default column definition option #106

Closed
amotl opened this issue Oct 6, 2022 · 0 comments · Fixed by crate/crate-python#556
Closed

SQLAlchemy/DDL: Support server_default column definition option #106

amotl opened this issue Oct 6, 2022 · 0 comments · Fixed by crate/crate-python#556

Comments

@amotl
Copy link
Member

amotl commented Oct 6, 2022

Introduction

CrateDB can use functions to generate server-side default values on columns. For example, the NOW() function can be used to auto-generate timestamp values.

crash <<EOL
    DROP TABLE IF EXISTS testdrive;
    CREATE TABLE IF NOT EXISTS "doc"."testdrive" (
      "timestamp" TIMESTAMP DEFAULT NOW() NOT NULL,
      "value" FLOAT
    );
    INSERT INTO testdrive (value) VALUES (42.42);
    INSERT INTO testdrive (value) VALUES (42.42);
    REFRESH TABLE testdrive;
    SELECT * FROM testdrive;
EOL

Objective

It would be sweet if we could make the CrateDB SQLAlchemy dialect support this feature appropriately.

Proposal

I think the right way is to implement the official SQLAlchemy column definition option server_default.

>>> import sqlalchemy as sa
>>> sa.Column("timestamp", sa.DateTime, server_default=sa.text("NOW()"))

-- https://docs.sqlalchemy.org/en/20/core/metadata.html#sqlalchemy.schema.Column.params.server_default

Example

The collab/sa-column-server-default branch has a corresponding example program.

@amotl amotl changed the title Check how RETURNING is fiddled back through SQLAlchemy Honor SQLAlchemy's server_default option Oct 6, 2022
@amotl amotl changed the title Honor SQLAlchemy's server_default option Honor SQLAlchemy's server_default column definition option Oct 6, 2022
@amotl amotl changed the title Honor SQLAlchemy's server_default column definition option SQLAlchemy: Honor server_default column definition option Mar 6, 2023
@amotl amotl changed the title SQLAlchemy: Honor server_default column definition option SQLAlchemy/DDL: Support server_default column definition option Mar 6, 2023
JanLikar referenced this issue in JanLikar/crate-python May 26, 2023
CrateDB's SQLAlchemy dialect now handles the `server_default` when generating
table DDL.

Although some implementations quote the values passed to `server_default`,
we don't do that here, to stay in line with SA docs.

Fix #454.
JanLikar referenced this issue in JanLikar/crate-python May 26, 2023
CrateDB's SQLAlchemy dialect now handles the `server_default` when generating
table DDL.

Fix #454.
JanLikar referenced this issue in JanLikar/crate-python May 31, 2023
CrateDB's SQLAlchemy dialect now handles the `server_default` when generating
table DDL.

Fix #454.
JanLikar referenced this issue in JanLikar/crate-python Jun 5, 2023
CrateDB's SQLAlchemy dialect now handles the `server_default` when generating
table DDL.

Fix #454.
JanLikar referenced this issue in JanLikar/crate-python Jun 8, 2023
CrateDB's SQLAlchemy dialect now handles the `server_default` when generating
table DDL.

Fix #454.
JanLikar referenced this issue in JanLikar/crate-python Jun 8, 2023
CrateDB's SQLAlchemy dialect now handles the `server_default` when generating
table DDL.

Fix #454.
JanLikar referenced this issue in JanLikar/crate-python Jun 8, 2023
CrateDB's SQLAlchemy dialect now handles the `server_default` when generating
table DDL.

Fix #454.
amotl referenced this issue in crate/crate-python Jun 9, 2023
CrateDB's SQLAlchemy dialect now handles the `server_default` when generating
table DDL.

Fix #454.
@amotl amotl transferred this issue from crate/crate-python Jun 16, 2024
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

Successfully merging a pull request may close this issue.

1 participant