Skip to content

NOW() not recognized as now() #18

@dargueta

Description

@dargueta

Describe the bug

NOW() is not recognized as equivalent to now() when used as a default value, even though SQL is case-insensitive.

To Reproduce

Given the following SQL:

ddl = """
CREATE TABLE asdf (
  t TIMESTAMP DEFAULT NOW()
);
"""
print(omymodels.create_models(ddl=ddl, models_type="dataclass")["code"])

The output is

import datetime
from dataclasses import dataclass


@dataclass
class Asdf:

    t: datetime.datetime = 'NOW()'  # Default value is wrong

Note that, while the datatype of the column is correct, the default value is a string instead of a call to datetime.datetime.now(). If we make NOW()` lowercase, we get the expected output.

import datetime
from dataclasses import dataclass


@dataclass
class Asdf:

    t: datetime.datetime = datetime.datetime.now()

n.b. the expected output has a bug in it which I'll file a separate ticket for

Expected behavior

SQL is case-insensitive, therefore now() and NOW() should behave identically and produce the same output.

Additional context

Python: 3.8.2
Version: 0.8.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions