title: How to pass the PostgreSQL query result into a variable in Airflow? (Postgres Operator or Postgres Hook)
body: <p>I'm planning to use PostgreSQL as my task meta info provider, so I want to run a few queries and get some data and pass it like a filled variable to another task.
  The problem is when I use <strong>PostgresHook</strong> I get the data but its in a python method that I cant access, in fact I see bellow line</p>
  <pre><code>[2021-08-23 13:00:12,628] {python.py:151} INFO - Done. Returned value was: [[1, &quot;inf_account&quot;,....]]
  </code></pre>
  <p>here is part of my code:</p>
  <pre><code>def _query_postgres(**context):
      &quot;&quot;&quot;
      Queries Postgres and returns a cursor to the results.
      &quot;&quot;&quot;
  
      postgres = PostgresHook(postgres_conn_id=&quot;aramis_postgres_connection&quot;)
      conn = postgres.get_conn()
      cursor = conn.cursor()
      mark_williams = cursor.execute(&quot; SELECT * FROM public.aramis_meta_task; &quot;)
  
      # iterate over to get a list of dicts
      details_dicts = [doc for doc in cursor]
  
      # serialize to json string
      details_json_string = json.dumps(details_dicts, default=json_util.default)
  
      task_instance = context['task_instance']
      task_instance.xcom_push(key=&quot;my_value&quot;, value=details_json_string)
      return details_json_string
  </code></pre>
  <p>but I don't know which variable should I use to access it or how to push it to XCOM so that i can use that returned value as a parameter to another bashoperator task(Spark for example).</p>
  <p><strong>PostgresOperator</strong> on the other hand, only returns <code>None</code> as result.</p>