darold / pgFormatter

A PostgreSQL SQL syntax beautifier that can work as a console program or as a CGI. On-line demo site at http://sqlformat.darold.net/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use of uninitialized value in pattern match in Beautify.pm line 968

Profpatsch opened this issue · comments

When trying to format the following query:

SELECT id, usergroups, entryval FROM foo.collections c WHERE (NULL::text IS NULL OR c.id = NULL::text) AND c.collection = 'foo'::text AND (FALSE::bool OR c.usergroups::text[] && ARRAY['620a6d408474d60001000000', 'public']::text[]) AND ( SELECT coalesce(bool_and(l.value = r.value), TRUE) FROM jsonb_each(c.entryval) l JOIN jsonb_each('{"organization":"620a6d408474d60001000000"}'::jsonb) r ON l.key = r.key)

with pg_format 5.5., I get:

Uncaught exception: Use of uninitialized value in pattern match (m//) at /nix/store/dlsxkvrlvq7y98l9476df39crz2i5cn6-perl5.36.0-pgformatter-5.5/bin/lib/pgFormatter/Beautify.pm line 968, <STDIN> line 1.
 at /nix/store/dlsxkvrlvq7y98l9476df39crz2i5cn6-perl5.36.0-pgformatter-5.5/bin/pg_format line 19, <STDIN> line 1.
	main::__ANON__("Use of uninitialized value in pattern match (m//) at /nix/sto"...) called at /nix/store/dlsxkvrlvq7y98l9476df39crz2i5cn6-perl5.36.0-pgformatter-5.5/bin/lib/pgFormatter/Beautify.pm line 968
	pgFormatter::Beautify::beautify(pgFormatter::Beautify=HASH(0x223a5c8)) called at /nix/store/dlsxkvrlvq7y98l9476df39crz2i5cn6-perl5.36.0-pgformatter-5.5/bin/lib/pgFormatter/CLI.pm line 170
	pgFormatter::CLI::beautify(pgFormatter::CLI=HASH(0x1940da0)) called at /nix/store/dlsxkvrlvq7y98l9476df39crz2i5cn6-perl5.36.0-pgformatter-5.5/bin/lib/pgFormatter/CLI.pm line 78
	pgFormatter::CLI::run(pgFormatter::CLI=HASH(0x1940da0)) called at /nix/store/dlsxkvrlvq7y98l9476df39crz2i5cn6-perl5.36.0-pgformatter-5.5/bin/pg_format line 49

vs pg_format 5.3:

SELECT
    id,
    usergroups,
    entryval
FROM
    foo.collections c
WHERE (NULL::text IS NULL
    OR c.id = NULL::text)
AND c.collection = 'foo'::text
AND (FALSE::bool
    OR c.usergroups::text[] && ARRAY['620a6d408474d60001000000', 'public']::text[])
AND (
    SELECT
        coalesce(bool_and(l.value = r.value), TRUE)
    FROM
        jsonb_each(c.entryval) l
        JOIN jsonb_each('{"organization":"620a6d408474d60001000000"}'::jsonb) r ON l.key = r.key)

Commit c2622c4 fixes this issue.

That works for me, thanks!

cc @marsam maybe we want to include this into the current nixpkgs release.

Is this fix already released? I think I am running into this problem at the moment.

Not release yet, you must install the development code to fix this issue for the moment.