Create a Python script that connects to a PostgreSQL database, reads data from a table named "products", performs some calculations on the data (e.g., calculating average price), and updates another table named "product_summary" with the calculated values.

To create a Python script that connects to a PostgreSQL database, reads data from a table named "products", performs some calculations on the data (e.g., calculating average price), and updates another table named "product_summary" with the calculated values, you can use the following code:

```python
import psycopg2

# Replace these values with your own database credentials
db_name = "your_database_name"
db_user = "your_database_user"
db_password = "your_database_password"
db_host = "your_database_host"
db_port = "your_database_port"

def connect_to_db():
    try:
        connection = psycopg2.connect(
            dbname=db_name,
            user=db_user,
            password=db_password,
            host=db_host,
            port=db_port
        )
        return connection
    except Exception as e:
        print(f"Error connecting to the database: {e}")
        return None

def read_products_data(connection):
    cursor = connection.cursor()
    query = "SELECT * FROM products;"
    cursor.execute(query)
    rows = cursor.fetchall()
    cursor.close()
    return rows

def calculate_average_price(products_data):
    total_price = 0
    num_products = len(products_data)

    for product in products_data:
        # Assuming the price is stored in the second column of the 'products' table
        total_price += product[1]

    average_price = total_price / num_products
    return average_price

def update_product_summary(connection, average_price):
    cursor = connection.cursor()
    query = f"UPDATE product_summary SET average_price = {average_price};"
    cursor.execute(query)
    connection.commit()
    cursor.close()

if __name__ == "__main__":
    connection = connect_to_db()

    if connection:
        products_data = read_products_data(connection)
        average_price = calculate_average_price(products_data)
        update_product_summary(connection, average_price)
        connection.close()
```

Replace the `db_name`, `db_user`, `db_password`, `db_host`, and `db_port` variables with your own database credentials. This script assumes that you have a table named "products" with a price column, and another table named "product_summary" with an average_price column.

Make sure to install psycopg2 package before running the script:

```bash
pip install psycopg2
```

You can then run the script using Python:

```bash
python script.py
```