{"id":37154557,"url":"https://github.com/bytebase/redshift-parser","last_synced_at":"2026-01-14T18:16:34.711Z","repository":{"id":305655069,"uuid":"1021912117","full_name":"bytebase/redshift-parser","owner":"bytebase","description":"Redshift parser based on ANTLR 4.","archived":true,"fork":false,"pushed_at":"2025-07-31T03:55:16.000Z","size":2430,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-15T13:10:29.440Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"ANTLR","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bytebase.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-18T06:33:06.000Z","updated_at":"2025-08-04T07:48:15.000Z","dependencies_parsed_at":"2025-07-21T11:29:30.880Z","dependency_job_id":null,"html_url":"https://github.com/bytebase/redshift-parser","commit_stats":null,"previous_names":["bytebase/redshift-parser"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bytebase/redshift-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytebase%2Fredshift-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytebase%2Fredshift-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytebase%2Fredshift-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytebase%2Fredshift-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bytebase","download_url":"https://codeload.github.com/bytebase/redshift-parser/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytebase%2Fredshift-parser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28430194,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T16:38:47.836Z","status":"ssl_error","status_checked_at":"2026-01-14T16:34:59.695Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2026-01-14T18:16:33.933Z","updated_at":"2026-01-14T18:16:34.698Z","avatar_url":"https://github.com/bytebase.png","language":"ANTLR","readme":"# Redshift Parser\n\nA comprehensive SQL parser for Amazon Redshift built with ANTLR 4, optimized for Redshift-specific syntax.\n\n## Overview\n\nThis project is a Go-based SQL parser specifically designed for Amazon Redshift. It originated as a fork of the PostgreSQL parser but has been restructured to focus exclusively on Redshift's unique syntax requirements.\n\n## Features\n\n- **Complete SQL Support**: Parses 200+ SQL statement types including DDL, DML, and advanced constructs\n- **Redshift-Specific Syntax**: Full support for Redshift extensions like `IDENTITY` columns, `DISTKEY`, `SORTKEY`, and more\n- **Redshift-Optimized**: Parser optimized exclusively for Redshift syntax and features\n- **Comprehensive Testing**: 200+ test cases covering real-world SQL scenarios\n- **High Performance**: Optimized for production use with parser reuse and efficient error handling\n\n## Installation\n\n```bash\ngo get github.com/bytebase/redshift-parser\n```\n\n## Quick Start\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/antlr4-go/antlr/v4\"\n    \"github.com/bytebase/redshift-parser\"\n)\n\nfunc main() {\n    // Parse a Redshift-specific CREATE TABLE statement\n    sql := `CREATE TABLE users (\n        id INT IDENTITY(1,1),\n        name VARCHAR(100),\n        email VARCHAR(255) UNIQUE\n    ) DISTKEY(id) SORTKEY(name);`\n    \n    // Create lexer and parser\n    input := antlr.NewInputStream(sql)\n    lexer := parser.NewRedshiftLexer(input)\n    stream := antlr.NewCommonTokenStream(lexer, 0)\n    p := parser.NewRedshiftParser(stream)\n    \n    // Parse the SQL\n    tree := p.Root()\n    \n    fmt.Println(\"Successfully parsed Redshift SQL!\")\n}\n```\n\n## Supported SQL Features\n\n### DDL (Data Definition Language)\n- `CREATE TABLE` with Redshift-specific options (DISTKEY, SORTKEY, IDENTITY)\n- `ALTER TABLE` with column modifications and constraints\n- `CREATE INDEX` with various index types\n- `CREATE VIEW` and materialized views\n- `CREATE FUNCTION` and stored procedures\n\n### DML (Data Manipulation Language)\n- `SELECT` with complex joins, subqueries, and window functions\n- `INSERT` with conflict resolution (`ON CONFLICT`)\n- `UPDATE` with joins and CTEs\n- `DELETE` with complex conditions\n- `MERGE` statements\n\n### Advanced Features\n- Common Table Expressions (CTEs)\n- Window functions and analytics\n- JSON operations and path expressions\n- Array operations\n- Regular expressions\n- Full-text search\n\n## Redshift-Specific Features\n\nThe parser is optimized for Redshift's unique SQL extensions:\n\n- **IDENTITY columns**: `CREATE TABLE t (id INT IDENTITY(1,1))`\n- **Distribution keys**: `DISTKEY(column_name)`\n- **Sort keys**: `SORTKEY(column_name)`\n- **Redshift built-in functions**: Comprehensive support for Redshift-specific functions\n- **Data types**: All Redshift-supported data types including extensions\n\n## Development\n\n### Prerequisites\n- Go 1.21+\n- ANTLR 4.13.2+\n\n### Building from Source\n\n1. **Clone the repository**:\n```bash\ngit clone https://github.com/bytebase/redshift-parser.git\ncd redshift-parser\n```\n\n2. **Generate parser code**:\n```bash\n./build.sh\n```\n\n3. **Run tests**:\n```bash\ngo test -v\n```\n\n### Project Structure\n\n```\nredshift-parser/\n├── RedshiftLexer.g4              # ANTLR lexer grammar\n├── RedshiftParser.g4             # ANTLR parser grammar\n├── build.sh                      # Code generation script\n├── redshift_lexer_base.go        # Base lexer implementation\n├── redshift_parser_base.go       # Base parser implementation\n├── keywords.go                   # 600+ SQL keywords\n├── builtin_function.go           # Built-in function definitions\n├── examples/                     # 200+ SQL test files\n├── parser_test.go                # Main test suite\n└── CLAUDE.md                     # Development guide\n```\n\n## Testing\n\nThe project includes comprehensive test coverage:\n\n```bash\n# Run all tests\ngo test -v\n\n# Run specific test\ngo test -run TestRedshiftParser -v\n\n# Run benchmarks\ngo test -bench=. -v\n\n```\n\nTest files are located in the `examples/` directory and cover:\n- Basic SQL operations\n- Complex queries with joins and subqueries\n- Redshift-specific syntax\n- Error handling scenarios\n- Performance benchmarks\n\n## Grammar Files\n\nThe parser is built using ANTLR 4 grammars:\n\n- **RedshiftLexer.g4**: Tokenization rules for SQL keywords, operators, and literals\n- **RedshiftParser.g4**: Grammar rules for SQL statement parsing\n\nAfter modifying grammar files, regenerate the Go code:\n\n```bash\n./build.sh\n```\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Add tests for your changes\n4. Ensure all tests pass\n5. Update documentation as needed\n6. Submit a pull request\n\n### Development Guidelines\n\n- Always run `./build.sh` before testing after grammar changes\n- Add test cases for new SQL syntax support\n- Follow existing code patterns and conventions\n- Use AWS Redshift documentation for syntax reference\n- Test against both PostgreSQL and Redshift engines\n\n## License\n\nThis project is licensed under the MIT License. See the grammar files for additional license information from the original PostgreSQL grammar contributors.\n\n## Acknowledgments\n\n- Based on the PostgreSQL grammar from [Tunnel Vision Labs](https://github.com/tunnelvisionlabs/antlr4-postgresql)\n- Forked from [Bytebase PostgreSQL Parser](https://github.com/bytebase/postgresql-parser)\n- Built with [ANTLR 4](https://github.com/antlr/antlr4)\n\n## Related Projects\n\n- [Bytebase](https://github.com/bytebase/bytebase) - Database DevOps platform\n- [PostgreSQL Parser](https://github.com/bytebase/postgresql-parser) - Original PostgreSQL parser\n- [ANTLR 4](https://github.com/antlr/antlr4) - Parser generator toolkit\n\n## Support\n\n- [GitHub Issues](https://github.com/bytebase/redshift-parser/issues) - Bug reports and feature requests\n- [AWS Redshift Documentation](https://docs.aws.amazon.com/redshift/latest/dg/c_SQL_commands.html) - SQL syntax reference\n- [ANTLR Documentation](https://github.com/antlr/antlr4/blob/master/doc/index.md) - Grammar development guide","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytebase%2Fredshift-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbytebase%2Fredshift-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytebase%2Fredshift-parser/lists"}