Python Lambda 函数成功但没有行显示已更新

Python Lambda function succeeds but no rows appear updated

我有一个 AWS lamda 函数正在更新我的 RDS。

def lambda_handler(event, context):

    connection = psycopg2.connect(user="****", password=****,
                                  host=****, port="****",
                                  database="****")
    
    cursor = connection.cursor()
    postgres_put_query = "UPDATE restaurant SET (item, price) = ('{0}','{1}') WHERE id = '{2}'".format(event['item'], event['price'], event['id'])
    cursor.execute(postgres_put_query)
    print(cursor.rowcount)

打印语句按预期打印 1 但是当我查看数据库中的数据时没有进行任何更新。

您需要调用 connection.commit() 来反映数据库中的变化

def lambda_handler(event, context):

    connection = psycopg2.connect(user="****", password=****,
                                  host=****, port="****",
                                  database="****")
    
    cursor = connection.cursor()
    postgres_put_query = "UPDATE restaurant SET (item, price) = ('{0}','{1}') WHERE id = '{2}'".format(event['item'], event['price'], event['id'])
    cursor.execute(postgres_put_query)
    print(cursor.rowcount)
    connection.commit()