agora inbox for postgres@postgres.berkeley.edu  
help / color / mirror / Atom feed
From: Bruce Thomson <bruce@comu11.auckland.ac.nz>
To: postgres@postgres.Berkeley.EDU
Cc: Bruce Thomson <bruce@ccvcom.auckland.ac.nz>
Subject: PQExec inside a C function?
Date: Tue, 28 Jun 1994 15:31:19 +1200 (NZST)
Message-ID: <9406280331.AA21637@comu11.auckland.ac.nz> (raw)

I am trying to call a user function from within the monitor that should
do some PQExec'd insertions into a table.

The function is shown below.



Unfortunately, I get the following results from 'monitor'. 
Can I execute embedded postquel statements in this way?

If not, what would be the best way to eventually call an external program,
and insert its results (from an output file) into a table, all from a
monitor retrieve command?


Thanks for any help.


-----------------------------------------------

Welcome to the POSTGRES terminal monitor



 
Go 
* define function isert_row (language="C", returntype=int4)
arg is (int4)
as "/home/sun/bruce/postgres/pqexec/insert.so"\g
 
Query sent to backend is "define function isert_row (language="C", returntype=int4) arg is (int4) as "/home/sun/bruce/postgres/pqexec/insert.so""
DEFINE
Go 
* load "/home/sun/bruce/postgres/pqexec/insert.so"\g
 
Query sent to backend is "load "/home/sun/bruce/postgres/pqexec/insert.so""
LOAD
Go 
* retrieve (result=insert_row(5))\g
 
Query sent to backend is "retrieve (result=insert_row(5))"
FATAL: no response from backend: detected in dump_data
 
Go 
* retrieve (twoval.all)\g
 
Query sent to backend is "retrieve (twoval.all)"
FATAL: no response from backend: detected in PQexec
 
Go 
* \q
Broken pipe



-----------------------------
#include <stdio.h>
#include "tmp/libpq.h"

int insert_row(x)
int x;
{
char append_line[100];  /* care not to run over the length */

PQsetdb ("external");
PQexec("begin");
sprintf(append_line,"append twovals(x1=%d,x2=%d)",x,x*2);
PQexec(append_line);
PQexec("end");
PQfinish(); 
return(0);
}
-------------------------------


-----------------------------------------------------------------------------

Bruce Thomson                                     bruce@comu11.auckland.ac.nz
                                                           e-mail for pgp key
-----------------------------------------------------------------------------


==============================================================================
   To add/remove yourself to/from the POSTGRES mailing list: send mail with 
   the subject line ADD or DEL to "postgres-request@postgres.Berkeley.EDU"

   If this fails, send mail to "post_questions@postgres.Berkeley.EDU" and
   a human will deal with it.  DO NOT post to the "postgres" mailing list.
==============================================================================



reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: postgres@postgres.berkeley.edu
  Cc: bruce@comu11.auckland.ac.nz, bruce@ccvcom.auckland.ac.nz
  Subject: Re: PQExec inside a C function?
  In-Reply-To: <9406280331.AA21637@comu11.auckland.ac.nz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox