{"id":13643247,"url":"https://github.com/cloudquery/pg_gpt","last_synced_at":"2025-04-05T17:08:42.774Z","repository":{"id":149101133,"uuid":"619130748","full_name":"cloudquery/pg_gpt","owner":"cloudquery","description":"Experimental extension that brings OpenAI API to your PostgreSQL to run queries in human language.","archived":false,"fork":false,"pushed_at":"2023-06-04T10:19:08.000Z","size":23,"stargazers_count":457,"open_issues_count":1,"forks_count":19,"subscribers_count":17,"default_branch":"main","last_synced_at":"2025-03-29T16:09:08.717Z","etag":null,"topics":["chatgpt","cloudquery","postgresql","rust","sql"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloudquery.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-03-26T11:12:31.000Z","updated_at":"2025-02-27T07:13:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"b5e81204-70c3-4d5c-98f3-cdc4a2df259c","html_url":"https://github.com/cloudquery/pg_gpt","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/cloudquery%2Fpg_gpt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudquery%2Fpg_gpt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudquery%2Fpg_gpt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudquery%2Fpg_gpt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloudquery","download_url":"https://codeload.github.com/cloudquery/pg_gpt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247369952,"owners_count":20927928,"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":["chatgpt","cloudquery","postgresql","rust","sql"],"created_at":"2024-08-02T01:01:44.526Z","updated_at":"2025-04-05T17:08:42.755Z","avatar_url":"https://github.com/cloudquery.png","language":"Rust","funding_links":[],"categories":["Browser-extensions","Rust"],"sub_categories":[],"readme":"# Postgres \u003c\u003e ChatGPT\n\nExperimental PostgreSQL extension that enables the use of OpenAI GPT API inside PostgreSQL, allowing for queries to be written using natural language.\n\n## Demo\n\nhttps://user-images.githubusercontent.com/1121616/228234378-40c796d3-0a38-465a-92da-9370fb21b93b.mp4\n\n(This demo uses data from the [Hacker News](https://www.cloudquery.io/integrations/hackernews/postgresql) and [Azure](https://www.cloudquery.io/integrations/azure/postgresql) CloudQuery plugins)\n\n## How does it work?\n\nThe extension sends a subset of the database schema to ChatGPT and asks it to generate a query based on this and the user input.\n\n## Before you start\n\n- **Note**: This plugins sends schema (without the data) to OpenAI GPT API, so it is not recommended to use it on production databases.\n- **Note**: This is an experimental plugin and not officially supported by CloudQuery.\n\n## Installation\n\nRequires [pgx](https://github.com/tcdi/pgx). Install this first:\n\n```bash\ncargo install --locked cargo-pgx\ncargo pgx init\n```\n\nNow you can install the extension:\n\n```bash\ngit clone https://github.com/cloudquery/pg_gpt\ncd pg_gpt\nexport OPENAI_KEY=\u003cYOUR_KEY\u003e\ncargo pgx run\n# will drop into psql shell\n```\n\n```sql\ncreate extension pg_gpt;\nset openai.key = '\u003cYOUR OPENAPI API KEY HERE\u003e'; -- set your key\nselect gpt('show me all open aws s3 buckets');\n-- will output the following query, so you can execute it\n-- select * from aws_s3_bucket;\n```\n\n## Available Functions\n\n- `gpt(text)` - Generates a query based on the user input and the full database schema. This works fine for databases with small schemas.\n- `gpt_tables(table_pattern, text)` - Similar to gpt, but only uses the tables that match the pattern. The pattern is passed to a `table_name LIKE` query, so `%` can be used as wildcard.\n\n## Installing the extension on an existing Postgres instance\n\nFirst run:\n\n```bash\ncargo pgx install\n```\n\nThis places the extension in the postgres extensions directory. Then, in your postgres instance, run:\n\n```sql\ncreate extension pg_gpt;\nset openai.key = '\u003cYOUR OPENAPI API KEY HERE\u003e';\n-- proceed to use the extension\n```\n\n## Limitations\n\n* Schema Size - Currently we use gpt-3.5-turbo, which is limited to 4096 tokens. Use `gpt_tables` to narrow down the set of tables.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudquery%2Fpg_gpt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloudquery%2Fpg_gpt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudquery%2Fpg_gpt/lists"}