{"id":37014080,"url":"https://github.com/flow-php/pg-query-ext","last_synced_at":"2026-01-14T01:23:53.952Z","repository":{"id":326531104,"uuid":"1104532648","full_name":"flow-php/pg-query-ext","owner":"flow-php","description":null,"archived":false,"fork":false,"pushed_at":"2025-12-12T10:56:41.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"1.x","last_synced_at":"2025-12-13T03:00:19.206Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","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/flow-php.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"norberttech","custom":"https://flow-php.com/sponsor"}},"created_at":"2025-11-26T10:42:25.000Z","updated_at":"2025-12-12T10:56:44.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/flow-php/pg-query-ext","commit_stats":null,"previous_names":["flow-php/pg-query-ext"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/flow-php/pg-query-ext","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flow-php%2Fpg-query-ext","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flow-php%2Fpg-query-ext/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flow-php%2Fpg-query-ext/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flow-php%2Fpg-query-ext/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flow-php","download_url":"https://codeload.github.com/flow-php/pg-query-ext/tar.gz/refs/heads/1.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flow-php%2Fpg-query-ext/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28407696,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T00:40:43.272Z","status":"ssl_error","status_checked_at":"2026-01-14T00:40:42.636Z","response_time":56,"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-14T01:23:53.341Z","updated_at":"2026-01-14T01:23:53.937Z","avatar_url":"https://github.com/flow-php.png","language":"C","funding_links":["https://github.com/sponsors/norberttech","https://flow-php.com/sponsor"],"categories":[],"sub_categories":[],"readme":"# pg_query PHP Extension\n\nA compiled PHP extension for PostgreSQL query parsing using [libpg_query](https://github.com/pganalyze/libpg_query).\n\n## Features\n\n- Parse PostgreSQL SQL queries into JSON AST\n- Generate query fingerprints for query grouping\n- Normalize SQL queries (replace literals with placeholders)\n- Parse PL/pgSQL functions\n- Split multiple SQL statements\n- Scan SQL into tokens\n\n## Installation\n\n### Using PIE (Recommended)\n\n[PIE](https://github.com/php/pie) is the modern PHP extension installer.\n\n**Prerequisites:** Install protobuf-c library on your system:\n\n```bash\n# Ubuntu/Debian\nsudo apt-get install libprotobuf-c-dev git make gcc\n\n# macOS with Homebrew\nbrew install protobuf-c\n\n# Fedora/RHEL\nsudo dnf install protobuf-c-devel git make gcc\n```\n\n**Install the extension:**\n\n```bash\n# Simple installation (auto-downloads libpg_query)\npie install flow-php/pg-query-ext\n\n# Or with a pre-installed libpg_query (must be version 17+)\npie install flow-php/pg-query-ext --with-pg-query=/usr/local\n```\n\nThe extension will automatically download and build libpg_query 17-latest if not found on your system.\n\n\u003e **Note:** This extension uses PostgreSQL 17 grammar (libpg_query 17-latest). It requires `postgres_deparse.h` which is only available in libpg_query 17+.\n\n### Requirements\n\n- PHP 8.2+\n- C compiler (gcc/clang)\n- git (for auto-downloading libpg_query)\n- make\n- protobuf-c library\n\n### Manual Build\n\n```bash\ncd src/extension/pg-query-ext\n\n# This will download and build libpg_query, then build the extension\nmake build\n\n# Run extension tests\nmake test\n\n# Install to system PHP (optional)\nmake install\n```\n\n### Using Nix\n\nFrom the Flow PHP monorepo root:\n\n```bash\n# Enter Nix shell with pg_query extension loaded and build tools available\nnix-shell --arg with-pg-query-ext true\n\n# Navigate to extension directory\ncd src/extension/pg-query-ext\n\n# Build and test\nmake test\n```\n\n## Usage\n\n```php\n// Parse SQL and return JSON AST\n$json = pg_query_parse('SELECT * FROM users WHERE id = 1');\n$ast = json_decode($json, true);\n\n// Generate fingerprint (same for structurally equivalent queries)\n$fp = pg_query_fingerprint('SELECT * FROM users WHERE id = 1');\n// Returns same fingerprint for: SELECT * FROM users WHERE id = 2\n\n// Normalize query (replace literals with $N placeholders)\n$normalized = pg_query_normalize(\"SELECT * FROM users WHERE name = 'John'\");\n// Returns: SELECT * FROM users WHERE name = $1\n\n// Split multiple statements\n$statements = pg_query_split('SELECT 1; SELECT 2; SELECT 3');\n// Returns: ['SELECT 1', ' SELECT 2', ' SELECT 3']\n\n// Scan SQL into tokens (returns protobuf data)\n$protobuf = pg_query_scan('SELECT 1');\n```\n\n## Loading the Extension\n\n### During Development\n\n```bash\nphp -d extension=./ext/modules/pg_query.so your_script.php\n```\n\n### In php.ini\n\n```ini\nextension=pg_query\n```\n\n## Functions Reference\n\n| Function                              | Description                       | Returns             |\n|---------------------------------------|-----------------------------------|---------------------|\n| `pg_query_parse(string $sql)`         | Parse SQL to JSON AST             | `string` (JSON)     |\n| `pg_query_fingerprint(string $sql)`   | Generate query fingerprint        | `string\\|false`     |\n| `pg_query_normalize(string $sql)`     | Normalize query with placeholders | `string\\|false`     |\n| `pg_query_parse_plpgsql(string $sql)` | Parse PL/pgSQL function           | `string` (JSON)     |\n| `pg_query_split(string $sql)`         | Split multiple statements         | `array\u003cstring\u003e`     |\n| `pg_query_scan(string $sql)`          | Scan SQL into tokens              | `string` (protobuf) |\n\n## Development\n\n```bash\n# Build and run tests\nmake test\n\n# Rebuild extension only (without rebuilding libpg_query)\nmake rebuild\n\n# Clean build artifacts\nmake clean\n\n# Remove everything including libpg_query\nmake distclean\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflow-php%2Fpg-query-ext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflow-php%2Fpg-query-ext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflow-php%2Fpg-query-ext/lists"}