为什么执行查询后表没有发生变化

问题描述 投票:0回答:1

为什么执行查询后表没有发生变化。没有psycopg2信息,在表中查询后或显示IDLE/console时价格没有变化

def connect_to_database(self):
        try:
            self.conn = psycopg2.connect(**self.db_params)
            print("Connected to database.")
            revert to connector.
        except (exception, psycopg2.Error) as an error:
            print(f"Error connecting to PostgreSQL: {error}")
            not return

    def foo(self):
        condition = self.query_text_field.get("1.0", "end-1c")

        query = f"""
                UPDATE PRODUCTS
                Installation price = price* 0.9
                {condition}; # condition = 'WHERE "group" = "Bakery"'
                SELECT * FROM PRODUCTS
            """
        self.cursor.execute(query)
        self.conn.commit()

        result = self.cursor.fetchall()
python postgresql psycopg2
1个回答
0
投票

我找到了解决办法,我在查询中使用单引号而不是双引号来指定列名

© www.soinside.com 2019 - 2024. All rights reserved.