title: PostgreSQL: Query has no destination for result data
body: <p>I am trying to fetch data from remote db by using dblink through function but getting an error "query has no destination for result data". I am using plpgsql language to do the same. </p>
  
  <p><strong>Function</strong>:  </p>
  
  <pre><code>CREATE OR REPLACE FUNCTION fun()
    RETURNS text AS
  $$
  begin
  select dblink_connect(
        'port=5432 dbname=test user=postgres password=****');
  
  WITH a AS (
  SELECT *
  FROM dblink(
      'SELECT slno,fname,mname,lname
      FROM    remote_tbl'
       ) AS t (slno int, fname text, mname text, lname text)
  )
  , b AS (
  INSERT INTO temptab1
  SELECT slno, name
  FROM   a
  )
  , c AS (
  INSERT INTO temptab2
  SELECT slno, name
  FROM   a
  )
  INSERT INTO temptab3
  SELECT slno, name
  FROM   a;
  
  
  select dblink_disconnect();
  end;
  $$ 
  LANGUAGE plpgsql;
  </code></pre>
  
  <p><strong>Calling Function</strong>:</p>
  
  <pre><code>select fun();
  </code></pre>
  
  <p><strong>Error</strong>: query has no destination for result data</p>