postgresql + dblink + insert with returning
<p>I need to insert a record in remote database and get the id inserted. What am I doing wrong?</p>
<pre><code>DECLARE

ticketvar mytable%rowtype;

SqlCommand TEXT;

BEGIN    

ticketvar.c1 := somevalue;
ticketvar.c2 := somevalue;

SqlCommand := 'INSERT INTO mytable ( c1, c2)  VALUES (||ticketvar.c1||, ||ticketvar.c2||) returning tid';

tid =  (select *  from dblink('mydatawrapper',SqlCommand)  AS t1(bigint tid)  );
</code></pre>
<p>...</p>
<p>It raises an error</p>
<blockquote>
<p>ERROR:  missing FROM-clause entry for table &quot;ticketvar&quot;</p>
</blockquote>
<p>With select statement, everything works just fine:</p>
<pre><code>result = (select *  from dblink('mydatawrapper','SELECT tid FROM mytable WHERE c1='||c1||'')  AS t1(bigint tid) );
</code></pre>