{"id":15724439,"url":"https://github.com/cldellow/ersatz-table-valued-functions","last_synced_at":"2025-06-23T18:07:19.913Z","repository":{"id":65404189,"uuid":"591735369","full_name":"cldellow/ersatz-table-valued-functions","owner":"cldellow","description":"A bad idea","archived":false,"fork":false,"pushed_at":"2023-01-22T18:09:28.000Z","size":12,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-02T16:19:45.559Z","etag":null,"topics":["sqlglot","sqlite"],"latest_commit_sha":null,"homepage":"","language":"Python","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/cldellow.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":"2023-01-21T17:45:49.000Z","updated_at":"2023-11-07T13:03:03.000Z","dependencies_parsed_at":"2023-02-12T12:00:49.476Z","dependency_job_id":null,"html_url":"https://github.com/cldellow/ersatz-table-valued-functions","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cldellow%2Fersatz-table-valued-functions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cldellow%2Fersatz-table-valued-functions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cldellow%2Fersatz-table-valued-functions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cldellow%2Fersatz-table-valued-functions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cldellow","download_url":"https://codeload.github.com/cldellow/ersatz-table-valued-functions/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cldellow%2Fersatz-table-valued-functions/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":258996419,"owners_count":22789972,"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":["sqlglot","sqlite"],"created_at":"2024-10-03T22:16:41.108Z","updated_at":"2025-06-23T18:07:19.889Z","avatar_url":"https://github.com/cldellow.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ersatz-table-valued-functions\n\n[![PyPI](https://img.shields.io/pypi/v/ersatz-table-valued-functions.svg)](https://pypi.org/project/ersatz-table-valued-functions/)\n[![Changelog](https://img.shields.io/github/v/release/cldellow/ersatz-table-valued-functions?include_prereleases\u0026label=changelog)](https://github.com/cldellow/ersatz-table-valued-functions/releases)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/cldellow/ersatz-table-valued-functions/blob/main/LICENSE)\n\nA bad idea.\n\n**ersatz** *(adj.)*: made or used as a substitute, typically an inferior one, for something else.\n\nSee also [datasette-ersatz-tablue-valued-functions](https://github.com/cldellow/datasette-ersatz-table-valued-functions/).\n\n## Installation\n\nInstall this library using `pip`:\n\n    pip install ersatz-table-valued-functions\n\n## Usage\n\nThis library lets you rewrite queries like:\n\n```sql\nSELECT root, square FROM tbl_squares(3)\n```\n\ninto queries like:\n\n```sql\nWITH _ersatz_1 AS (\n  SELECT\n    JSON_EXTRACT(value, '$[0]') AS \"root\",\n    JSON_EXTRACT(value, '$[1]') AS \"square\"\n  FROM JSON_EACH((SELECT tbl_squares(3)))\n)\nSELECT root, square FROM _ersatz_1\n```\n\nThat is: it translates a query that _looks_ like it needs a table-valued function\ninto one that uses a scalar-valued function that returns a JSON 2D array.\n\n\nTo use it:\n\n```python\nfrom ersatz_table_valued_functions import rewrite\n\nrewrite('SELECT root, square FROM tbl_squares(3)', { 'TBL_SQUARES': ['root', 'square'] })\n```\n\n\n## Development\n\nTo contribute to this library, first checkout the code. Then create a new virtual environment:\n\n    cd ersatz-table-valued-functions\n    python -m venv venv\n    source venv/bin/activate\n\nNow install the dependencies and test dependencies:\n\n    pip install -e '.[test]'\n\nTo run the tests:\n\n    pytest\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcldellow%2Fersatz-table-valued-functions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcldellow%2Fersatz-table-valued-functions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcldellow%2Fersatz-table-valued-functions/lists"}