From: | "Haszlakiewicz, Eric" <EHASZLA(at)transunion(dot)com> |
---|---|
To: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | retrieving function raise messages in ecpg embedded sql code |
Date: | 2012-06-18 21:35:17 |
Message-ID: | 4EB74494E20A13478F64930FDE244D640266EBDD@CHO3WUC9MBX11.corp.transunion.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
I'm trying to get some additional information back from a trigger to my embedded SQL
program, to essentially emulate Informix's way of generating serial values.
I can get the serial to be generated, but I'm trying to figure out how to get the
generated value back to my program with minimal changes to the SQL.
I have a trigger that looks a bit like this:
create table mytable (mycol integer, mycol2 integer);
create or replace function functionfoo() returns trigger as $QUOTED$
BEGIN
new.mycol = nextval(TG_TABLE_NAME || '_mycol_seq');
raise INFO using MESSAGE = 'A Message';
return new;
END;
$QUOTED$ LANGUAGE 'plpgsql';
create trigger mytable_insert_trig before insert on mytable for each row when (new.mycol = 0) execute procedure functionfoo();
My ecpg program looks a bit like this:
exec sql begin declare section;
long mycol1;
long mycol2;
const char *mydb;
exec sql end declare section;
mycol1 = 0;
mycol2 = 1;
mydb = "mydb";
exec sql connect to :mydb;
exec sql prepare row_insert from "insert into mytable values (?, ?)";
EXEC SQL EXECUTE row_insert using :mycol1, mycol2;
I can't figure out how to retrieve the message raised by the trigger. I know it's
available in some cases, because I see the message when I insert a row through psql,
but even things like this:
printf("%s\n", PQerrorMessage(ECPGget_PGconn(mydb)));
return nothing useful. Is there a way to get this information?
Thanks,
eric
From | Date | Subject | |
---|---|---|---|
Next Message | Paul Jones | 2012-06-18 21:49:32 | Fine-grained replication? |
Previous Message | Chris Schnaufer | 2012-06-18 21:23:23 | Composite Types, arrays, and functions |