Skip to content

How can I insert null value in some columns #522

@SergiusAC

Description

@SergiusAC

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions