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

autoincrement int with create_table() #751

Open
Krogsager opened this issue Sep 12, 2023 · 0 comments
Open

autoincrement int with create_table() #751

Krogsager opened this issue Sep 12, 2023 · 0 comments

Comments

@Krogsager
Copy link

Hi,
Given this SQL statement I can create a new table with an pk that increments itself.

CREATE TABLE job_queue (
    id INT IDENTITY(1,1) PRIMARY KEY,
    date_created DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    job_id VARCHAR(30)
);

Is there an equivalent way to do it with pypika?

query = Query \
    .create_table("job_queue") \
    .columns(
        Column("id", # question goes here
        Column("date_created", "DATETIME", nullable=False, default='CURRENT_TIMESTAMP'),
        Column("job_id", "VARCHAR(30)", nullable=True),
    ) \
    .unique("job_id") \
    .primary_key("id")

My bonus question: CURRENT_TIMESTAMP is database dependendt. It could also be NOW() or GETDATE(), but I'm using mssql/odbc. Does pypika have a variable for it?

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

1 participant