Example use of ASSERT with PostgreSQL

I would assume you try todo smth similar?

so=# select count(*) from pg_database;
 count
-------
    21
(1 row)

so=# do $$ begin assert (select count(*) from pg_database) = 21, 'not 21!';end;$$;
DO
so=# do $$ begin assert (select count(*) from pg_database) = 22, 'not 22!';end;$$;
ERROR:  not 22!
CONTEXT:  PL/pgSQL function inline_code_block line 1 at ASSERT

do $$
    begin
        ASSERT 1 = 2;
    end;
$$ LANGUAGE plpgsql;

But note, it works only starting from PostgreSql 9.5. In older versions you can define your own assert-function such like this

CREATE OR REPLACE FUNCTION __assert(boolean) RETURNS VOID AS $$
    BEGIN
        IF NOT $1 THEN
            RAISE EXCEPTION 'ASSERTING FAILED';
        END IF;
    END;
$$ LANGUAGE plpgsql;

And then use in this way

do $$
    declare
        tmp char;
    begin
        tmp := __assert(tmp_to_https('https') = 'https');
    end;
$$ LANGUAGE plpgsql;