Thread: Making a function call from within a transaction block.

Making a function call from within a transaction block.

From
Joshua Moore-Oliva
Date:
I am attempting to make this test work..  I have three tables

CREATE TABLE test1 (
    my_id int
);

CREATE TABLE test2 (
    my_id int
);

CREATE TABLE test3 (
    my_id int
);

And the function

CREATE FUNCTION addTest2Value( int ) RETURNS integer AS '
DECLARE
  value ALIAS FOR $1;
BEGIN
    INSERT INTO test2 VALUES( value );

  RETURN 1;
END;
' LANGUAGE 'plpgsql';


What I am attempting to do is this

BEGIN;

INSERT INTO test1 VALUES ( 1 );

addTest2Value( 2 );

INSERT INTO test3 VALUES ( 3 );

COMMIT;

However I get a syntax error at the addTest2Value.

If I use SELECT addTest2Value( 2 ); from what I've read in the docs I believe
that that will cause this routine to stop at the select and return to the
libpq-fe C interface...

I've also tried PERFORM addTest2Value but that is apparently only available
within a plpgsql function...

Any hints?

Thanks, Josh.

Re: Making a function call from within a transaction block. -- ignore

From
Joshua Moore-Oliva
Date:
I went ahead and tried this, and indeed it works..  nevermind :).. s orry for
the noise.

Josh.

On March 12, 2003 06:21 pm, you wrote:
> I am attempting to make this test work..  I have three tables
>
> CREATE TABLE test1 (
>       my_id int
> );
>
> CREATE TABLE test2 (
>       my_id int
> );
>
> CREATE TABLE test3 (
>       my_id int
> );
>
> And the function
>
> CREATE FUNCTION addTest2Value( int ) RETURNS integer AS '
> DECLARE
>   value ALIAS FOR $1;
> BEGIN
>       INSERT INTO test2 VALUES( value );
>
>   RETURN 1;
> END;
> ' LANGUAGE 'plpgsql';
>
>
> What I am attempting to do is this
>
> BEGIN;
>
> INSERT INTO test1 VALUES ( 1 );
>
> addTest2Value( 2 );
>
> INSERT INTO test3 VALUES ( 3 );
>
> COMMIT;
>
> However I get a syntax error at the addTest2Value.
>
> If I use SELECT addTest2Value( 2 ); from what I've read in the docs I
> believe that that will cause this routine to stop at the select and return
> to the libpq-fe C interface...
>
> I've also tried PERFORM addTest2Value but that is apparently only available
> within a plpgsql function...
>
> Any hints?
>
> Thanks, Josh.