0

I have a simple unit test to run in the pgtab https://pgtap.org/documentation.html#is as shown below

BEGIN;
    SELECT plan(12);
    -- Run the tests.

    do
    $$
    declare
        v_expected      varchar(100);;
    begin
        SELECT has_table('unit_test_expected_results');
    end;
    $$;

    -- Finish the tests and clean up.
    SELECT * FROM finish();
    ROLLBACK;
END

When I write the SELECT has_table('unit_test_expected_results'); inside the begin and end I am facing the below error

[2021-06-01 23:50:58] [42601] ERROR: query has no destination for result data
[2021-06-01 23:50:58] Hint: If you want to discard the results of a SELECT, use PERFORM instead.
[2021-06-01 23:50:58] Where: PL/pgSQL function inline_code_block line 5 at SQL statement

Any help will be appreciated

THis is the function from pgtab extension

create function has_table(name, text) returns text
    language sql
as
$$
SELECT ok( _rexists( '{r,p}'::char[], $1 ), $2 );
$$;

alter function has_table(name, text) owner to postgres;

If I write below code

begin
    SELECT has_table('unit_test_expected_results') INTO v_expected;
end;
OR
 begin
    PERFORM has_table('unit_test_expected_results');
end;

This works, but there are no result in the output window, however, if I write outside the begin and end everythings works perfectly

San Jaisy
  • 15,327
  • 34
  • 171
  • 290

1 Answers1

0

Anyone struggling with this issue can be refer here https://www.postgresql.org/docs/9.5/plpgsql-control-structures.html

CREATE or REPLACE FUNCTION get_test() RETURNS SETOF integer AS
            $BODY$
                
            BEGIN
                    RETURN QUERY SELECT has_table('unit_test_expected_results');
             END;
            $BODY$
            LANGUAGE plpgsql;
San Jaisy
  • 15,327
  • 34
  • 171
  • 290