Files
graphify/tests/fixtures/sample_plpgsql.sql
T
safishamsi 49df466385 fix(sql): recover CREATE FUNCTION/PROCEDURE from tree-sitter ERROR nodes (#1910)
tree-sitter-sql parses PL/pgSQL CREATE FUNCTION statements (OUT/INOUT
params, tagged dollar quotes, PERFORM/:= body statements) as ERROR
nodes, and the dispatch loop had no branch for them, so the functions
were silently dropped from the graph.

Handle ERROR nodes inside walk() (they can nest inside a merged
create_function during multi-statement error recovery) and dispatch
top-level ERROR statements to it. The branch regex-scans the raw node
text for every CREATE [OR REPLACE] FUNCTION/PROCEDURE, mirroring the
existing fb_proc_or_trigger and has_error fallbacks, with a name class
that keeps schema-qualified names (exposed.important_function) whole.
The PL/pgSQL body is not scanned for FROM/JOIN references to avoid
junk reads_from targets, and node ids match the clean create_function
branch so seen_ids dedups consistently.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-15 10:58:57 +01:00

28 lines
538 B
PL/PgSQL

CREATE TABLE accounts (
id INT PRIMARY KEY,
name TEXT
);
CREATE FUNCTION exposed.important_function(a int, OUT fuzz text) LANGUAGE plpgsql AS $$
BEGIN
PERFORM 1;
fuzz := 'x';
END
$$;
CREATE OR REPLACE FUNCTION tagged_quote_fn(n int) RETURNS int LANGUAGE plpgsql AS $fn$
DECLARE
total int := 0;
BEGIN
total := total + n;
RETURN total;
END
$fn$;
CREATE FUNCTION plain_sql_fn() RETURNS int LANGUAGE sql AS 'SELECT 1';
CREATE TABLE audit_log (
id INT PRIMARY KEY,
account_id INT REFERENCES accounts
);