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

How can I insert null value in some columns #522

Open
SergiusAC opened this issue Nov 19, 2024 · 0 comments
Open

How can I insert null value in some columns #522

SergiusAC opened this issue Nov 19, 2024 · 0 comments

Comments

@SergiusAC
Copy link

I need to execute INSERT query where some columns should be null. How can I do this?

My code example:

query = """
DECLARE $user_id AS String;
DECLARE $tg_user_id AS String;
DECLARE $activate_token AS String;
DECLARE $notifications_enabled AS Bool;
DECLARE $created_at AS Datetime;

INSERT INTO tg_users (user_id, tg_user_id, activate_token, notifications_enabled, created_at)
VALUES ($user_id, $tg_user_id, $activate_token, $notifications_enabled, $created_at);
"""
params = {
    "$user_id": (user_id.encode(), ydb.PrimitiveType.String),
    "$tg_user_id": None, # this column should be NULL
    "$activate_token": (activate_token.encode(), ydb.PrimitiveType.String),
    "$notifications_enabled": (notifications_enabled, ydb.PrimitiveType.Bool),
    "$created_at": (int(datetime.now().timestamp()), ydb.PrimitiveType.Datetime),
}
async with await self.tx.execute(query, params):
    pass
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