You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] JSQLParser 5.4-SNAPSHOT : Postgresql : Parser considers subsequent "CREATE FUNCTION" statements as a single statement #2322
Always check against the Latest SNAPSHOT of JSQLParser and the Syntax Diagram
Failing SQL Feature:
What I encountered is not exactly an error, because the parser does not throw an exception, but subsequent CREATE FUNCTION statements are put into a single CreateFunction object, with everything in-between the start of the first one until the end of the last one becoming part of CreateFunction#getFunctionDeclarationParts.
SQL Example:
Simplified Query Example, focusing on the failing feature
createtableif not exists test_table (
id bigintnot null
);
create or replacefunctiontest_fn_1(
target text,
characters text
) returns booleanas $$
selecttrim($2from $1) <> $1
$$ language sql immutable;
create or replacefunctiontest_fn_2(
target text,
characters text
) returns booleanas $$
select position(repeat(first_char, 2) intranslate(
$1, $2, repeat(first_char, length($2))
)) >0from (values (left($2, 1))) params(first_char)
$$ language sql immutable;
createtableif not exists test_table_2 (
id bigintnot null
);
Software Information:
JSqlParser version 5.4-SNAPSHOT
Database: PostgreSQL
Extra info
The AST can be seem here, the parser consider both functions one single "node"/"statement", while the create table statements are parsed correctly
changed the title [-][BUG] JSQLParser 5.4-SNAPSHOT : Postgresql : Parser considers subsequent functions as single function.[/-][+][BUG] JSQLParser 5.4-SNAPSHOT : Postgresql : Parser considers subsequent "CREATE FUNCTION" statements as a single statement[/+]on Oct 7, 2025
I was searching for similar issues and found that "WITH FUNCTION" syntax was recently implemented, which makes it easier for implementing a PR in the future.
I found a workaround. By not using dolar sign ($) when refering to the function parameters, the parser behaves normally, as can be seen here
createtableif not exists test_table (
id bigintnot null
);
create or replacefunctiontest_fn_1(
target text,
characters text
) returns booleanas $$
selecttrim(test_fn_1.charactersfromtest_fn_1.target) <>test_fn_1.target
$$ language sql immutable;
create or replacefunctiontest_fn_2(
target text,
characters text
) returns booleanas $$
select position(repeat(first_char, 2) intranslate(
test_fn_2.target, test_fn_2.characters, repeat(first_char, length(test_fn_2.characters))
)) >0from (values (left(test_fn_2.characters, 1))) params(first_char)
$$ language sql immutable;
createtableif not exists test_table_2 (
id bigintnot null
);
With that said, I might make a PR in the future when the workaround becomes cumbersome to maintain.
Activity
[-][BUG] JSQLParser 5.4-SNAPSHOT : Postgresql : Parser considers subsequent functions as single function.[/-][+][BUG] JSQLParser 5.4-SNAPSHOT : Postgresql : Parser considers subsequent "CREATE FUNCTION" statements as a single statement[/+]manticore-projects commentedon Oct 8, 2025
You are certainly correct, parsing
FunctionorProcedureis extremely weak and not in our scope.However, PRs and improvements are welcome.
LouizFC commentedon Oct 8, 2025
I was searching for similar issues and found that "WITH FUNCTION" syntax was recently implemented, which makes it easier for implementing a PR in the future.
I found a workaround. By not using dolar sign ($) when refering to the function parameters, the parser behaves normally, as can be seen here
With that said, I might make a PR in the future when the workaround becomes cumbersome to maintain.
Thanks for maintaining this project.