schemacrawler / SchemaCrawler

Free database schema discovery and comprehension tool
http://www.schemacrawler.com/
Other
1.58k stars 200 forks source link

Postgres Trigger getActionStatement not returning expected body #1418

Closed JessicaF closed 5 months ago

JessicaF commented 6 months ago

Description

Postgres trigger file contents:

CREATE OR REPLACE FUNCTION public.last_updated()
    RETURNS trigger
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE NOT LEAKPROOF
AS $BODY$
BEGIN
    NEW.last_update = CURRENT_TIMESTAMP;
    RETURN NEW;
END 
$BODY$;

ALTER FUNCTION public.last_updated()
    OWNER TO postgres;

Current Result getActionStatement() currently returns:

EXECUTE FUNCTION last_updated()

Expected Result Expected to return the trigger body

How to Reproduce

No response

Relevant log output

No response

SchemaCrawler Version

16.20.7

Java Version

11.0.21

Operating System and Version

MacOS (Apple M1 Pro) Sonoma (14.2.1)

Relational Database System and Version

PostgresQL 13.10

JDBC Driver and Version

42.5.0

sualeh commented 6 months ago

@JessicaF SchemaCrawler provides information from information_schema.triggers, which in your case, is simply EXECUTE FUNCTION last_updated(). The definition of public.last_updated() will be provided along with other details of the function. Please make sure that you are crawling routines also, in your code. By default, SchemaCrawler does not crawl routines.

JessicaF commented 6 months ago

Thank you for your response! I've found another potential issue within the same database but for a different trigger:

CREATE TRIGGER film_fulltext_trigger
    BEFORE INSERT OR UPDATE 
    ON public.film
    FOR EACH ROW
    EXECUTE FUNCTION tsvector_update_trigger('fulltext', 'pg_catalog.english', 'title', 'description');

The getActionStatement method is returning

EXECUTE FUNCTION tsvector_update_trigger('fulltext', 'pg_catalog.english', 'title', 'description')EXECUTE FUNCTION tsvector_update_trigger('fulltext', 'pg_catalog.english', 'title', 'description')

The expected output is just EXECUTE FUNCTION tsvector_update_trigger('fulltext', 'pg_catalog.english', 'title', 'description')

sualeh commented 6 months ago

@JessicaF I will fix this issue. It may need a change to the catalog model for triggers.

sualeh commented 5 months ago

@JessicaF Please use SchemaCrawler v16.21.1