Skip to content

Ignore CreateFunctionStmt node when using pgquery parser#1116

Merged
gfx merged 4 commits intosqldef:masterfrom
winebarrel:ignore_CreateFunctionStmt_in_pgquery
Feb 3, 2026
Merged

Ignore CreateFunctionStmt node when using pgquery parser#1116
gfx merged 4 commits intosqldef:masterfrom
winebarrel:ignore_CreateFunctionStmt_in_pgquery

Conversation

@winebarrel
Copy link
Contributor

If you use pgquery, CREATE FUNCTION will cause an error, so ignore it.

(In our schema, generic parser causes errors, so we want to use pgquery parser.)

$ psqldef --version
3.9.4 (d9016f9)

$ psql -h localhost -U postgres
psql (18.1)
Type "help" for help.

postgres=# CREATE OR REPLACE FUNCTION increment(i integer) RETURNS integer AS $$
BEGIN
RETURN i + 1;
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION

$ export PSQLDEF_PARSER=pgquery
$ psqldef --export -h localhost -U postgres postgres
2026/02/02 17:29:37 unknown node in parseStmt: &pg_query.Node_CreateFunctionStmt{CreateFunctionStmt:(*pg_query.CreateFunctionStmt)(0x1400f9937a0)}

@codecov
Copy link

codecov bot commented Feb 2, 2026

Codecov Report

❌ Patch coverage is 33.33333% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
parser/node.go 0.00% 2 Missing ⚠️
schema/parser.go 0.00% 2 Missing ⚠️
Files with missing lines Coverage Δ
database/postgres/parser.go 3.07% <100.00%> (+1.87%) ⬆️
parser/node.go 52.62% <0.00%> (-0.12%) ⬇️
schema/parser.go 91.26% <0.00%> (-0.18%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@winebarrel winebarrel force-pushed the ignore_CreateFunctionStmt_in_pgquery branch from 420e8c0 to 65ca2ae Compare February 2, 2026 08:58
@gfx
Copy link
Contributor

gfx commented Feb 3, 2026

@winebarrel

Greetings! 👋

This PR itself is LGTM, but I'd like to share my plan: I'll remove pgquery entirely at v4.0.0.

Hope I fix all the bugs in the generic parser.

@gfx gfx enabled auto-merge February 3, 2026 05:22
@gfx gfx added this pull request to the merge queue Feb 3, 2026
Merged via the queue into sqldef:master with commit 2bfb30d Feb 3, 2026
24 of 25 checks passed
@sqldef-bot sqldef-bot bot mentioned this pull request Feb 3, 2026
@gfx
Copy link
Contributor

gfx commented Feb 3, 2026

Fixed the root cause of the issue: #1120

@winebarrel
Copy link
Contributor Author

@gfx Thank you Marge :-)

The currently known bug is that it is not possible to export tables like the one below.
(There are probably other bugs as well.)

% psql -h localhost -U postgres
psql (18.1)
Type "help" for help.

postgres=# create table load (id int);
CREATE TABLE
postgres=# create index idx_load_id on load (id);
CREATE INDEX

% psqldef --export -h localhost -U postgres postgres
2026/02/03 14:45:29 WARN Generic parser failed on full SQL, using pgquery fallback error="found syntax error when parsing DDL \"CREATE INDEX idx_load_id ON public.load USING btree (id)\": syntax error at line 1, column 41 near 'load'\n  CREATE INDEX idx_load_id ON public.load USING btree (id)\n                                          ^"
CREATE TABLE "public"."load" (
    "id" integer
);

@winebarrel winebarrel deleted the ignore_CreateFunctionStmt_in_pgquery branch February 3, 2026 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants