{"id":14973868,"url":"https://github.com/tshprecher/antlr_psql","last_synced_at":"2025-10-27T05:31:06.332Z","repository":{"id":38272735,"uuid":"121357591","full_name":"tshprecher/antlr_psql","owner":"tshprecher","description":"ANTLR v4 grammar for Postgres SQL v10 (work in progress)","archived":false,"fork":false,"pushed_at":"2022-09-22T17:53:59.000Z","size":6505,"stargazers_count":76,"open_issues_count":11,"forks_count":31,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-09-28T18:05:21.946Z","etag":null,"topics":["antlr","antlr4","grammar","postgres","postgresql","psql","sql"],"latest_commit_sha":null,"homepage":"","language":"TSQL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tshprecher.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-13T08:31:16.000Z","updated_at":"2024-05-05T07:09:21.000Z","dependencies_parsed_at":"2022-08-24T23:40:44.315Z","dependency_job_id":null,"html_url":"https://github.com/tshprecher/antlr_psql","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tshprecher%2Fantlr_psql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tshprecher%2Fantlr_psql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tshprecher%2Fantlr_psql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tshprecher%2Fantlr_psql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tshprecher","download_url":"https://codeload.github.com/tshprecher/antlr_psql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219861812,"owners_count":16555984,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["antlr","antlr4","grammar","postgres","postgresql","psql","sql"],"created_at":"2024-09-24T13:49:36.526Z","updated_at":"2025-10-27T05:30:59.480Z","avatar_url":"https://github.com/tshprecher.png","language":"TSQL","funding_links":[],"categories":[],"sub_categories":[],"readme":"*WORK IN PROGRESS*\n\n# Antlr4 grammar for PostgresSQL v10.\n\nThis project is in development. See `/test_coverage.html` for a breakdown of test results\nby query type. Development is test driven, with tests  generated by scraping sql commands\ndirectly from the source postgres repo. See the scripts section below for details.\n\n# Setup\n\nThis project was built on MacOs v.10.14 using\n   - Maven v.3.3.9\n   - Python v.2.7.13\n   - Java v.1.8.0_144\n\nMaven and Java are used for building and testing. Some scripts use Python. \n\n# Generating the parser\n\nTo generate the Java parser code used for testing, run ` mvn compile`.\n\n# Testing\n\nTest queries live in `src/test/resources` categorized by query type. Each has been\nscraped from code in the source postgres repo and each query type has a Java test harness.\nFor example, running `mvn -Dtest=SelectCommandTest test` runs tests against all `SELECT`\nqueries. To run tests against all queries, run `mvn test`.\n\nMost tests fail simply because this project is incomplete. The development process\nhas been test -\u003e fail -\u003e pick a failing query -\u003e fix it. Addressing the root cause\nof a single failing test often fixes others, although diminishing returns applies\nas total accuracy increases.\n\nNote that since each test lives in its own file and filesystems have minimum page sizes\n(e.g. 4K), the size of this repo can be over 80MB. Having each test in single file\nhas been helpful for debugging. Test queries may be consolidated into fewer files\nwhen this project reaches a stable state.\n\n# Scripts\n\n## Generating test files\n\nAs mentioned, tests have been generated from the official postgres repo\n(https://github.com/postgres/postgres). To regenerate them, fetch the repository\nat the desired version and run `./scripts/gen_psql_tests src/test/regress/sql /tmp/my_local_psql_tests/`\nwhere `src/test/regress/sql` is a directory in the source postgres project.\n\n## Parsing a specific query\n\nSometimes it is useful to see exactly where the parser fails on a specific query.\nYou could use [IntelliJ Idea Plugin for ANTLR v4](https://github.com/antlr/intellij-plugin-v4) for testing.\nAlso there's a script for that. To see where the parser fails on `selectttt 1`, run `./scripts/parse \"selectttt 1\" stmt`.\nThe first argument is the query and the second the grammar rule, with `stmt` being the root rule defined\nin `PostgreSQLParser.g4`.\n\n## Generate test coverage report\n\nThe `/test_coverage.html` test coverage report can be generated from piping a script that runs all\nthe tests and filters out summary lines into one that formats those lines into an html table.\nSimply run `./scripts/get_test_output | ./scripts/format_test_results \u003e test_coverage.html`. Note\nthat this can take a minute through the entire suite.\n\n`./scripts/get_test_output` also fills `failed.log` with the names of currently failed scripts.\nSometimes small changes in parser could cause a decrease of the success rates in the coverage report.\n`scripts/print_uncommitted_failed_sql` prints to console a code of the statements that previously were\nsuccess and now have status 'failed'. In normal way the length of `failed.log` should only decrease.\n\n\n\n\n\n\n\n\n  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftshprecher%2Fantlr_psql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftshprecher%2Fantlr_psql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftshprecher%2Fantlr_psql/lists"}