input: Write a python function to connect to a PostgreSQL database using psycopg2, execute a query to fetch all rows from a given table, and return the results in JSON format using Flask.
  assert get_data() == jsonify([('row1_col1', 'row1_col2'), ('row2_col1', 'row2_col2')])
  assert get_data() == jsonify([])
output: def get_data():
      import psycopg2
      import json
      from flask import Flask, jsonify
  
      app = Flask(__name__)
  
      @app.route('/data', methods=['GET'])
      def fetch_data():
          try:
              # Connect to your postgres DB
              conn = psycopg2.connect("dbname=yourdbname user=yourusername password=yourpassword host=yourhost")
  
              # Open a cursor to perform database operations
              cur = conn.cursor()
  
              # Execute a query
              cur.execute("SELECT * FROM your_table")
  
              # Retrieve query results
              rows = cur.fetchall()
  
              # Close communication with the database
              cur.close()
              conn.close()
  
              # Convert rows to JSON
              return jsonify(rows)
          except Exception as e:
              return jsonify({"error": str(e)})
  
      return fetch_data