{"id":24443531,"url":"https://github.com/christophgil/bash_builtin_sql_db","last_synced_at":"2026-04-12T05:31:34.190Z","repository":{"id":271019747,"uuid":"912169556","full_name":"christophgil/bash_builtin_SQL_DB","owner":"christophgil","description":"Bash builtins for using Postgresql and SQLite SQL databases in Bash script ","archived":false,"fork":false,"pushed_at":"2025-01-19T13:02:56.000Z","size":80,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-14T03:13:36.733Z","etag":null,"topics":["bash","bash-builtin","bashbuiltin","c","clang","database","databases","gcc","module","plugin","postgresql","sql","sql-query","sql-server","sqlite-database","sqlite3"],"latest_commit_sha":null,"homepage":"","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/christophgil.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}},"created_at":"2025-01-04T19:53:42.000Z","updated_at":"2025-01-19T13:02:57.000Z","dependencies_parsed_at":"2025-01-04T21:28:10.927Z","dependency_job_id":null,"html_url":"https://github.com/christophgil/bash_builtin_SQL_DB","commit_stats":null,"previous_names":["christophgil/bash_builtin_sql_db"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christophgil%2Fbash_builtin_SQL_DB","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christophgil%2Fbash_builtin_SQL_DB/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christophgil%2Fbash_builtin_SQL_DB/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christophgil%2Fbash_builtin_SQL_DB/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/christophgil","download_url":"https://codeload.github.com/christophgil/bash_builtin_SQL_DB/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243515566,"owners_count":20303258,"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":["bash","bash-builtin","bashbuiltin","c","clang","database","databases","gcc","module","plugin","postgresql","sql","sql-query","sql-server","sqlite-database","sqlite3"],"created_at":"2025-01-20T22:15:55.472Z","updated_at":"2025-12-30T22:16:02.932Z","avatar_url":"https://github.com/christophgil.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bash_builtin_SQL_DB\n\nBash extensions for Postgresql and SQLite SQL databases in Bash scripts.\n\n\n\n\n\n\n\n\n# Summary\n\nBash is the most widely used UNIX shell.  Using SQL databases intensively in Bash scripts is slow\nbecause there is no integrated command for accessing SQL databases as in other programming\nlanguages.\n\nSince the CLI programs /usr/bin/psql or /usr/bin/sqlite3 are called for each query, there is a large\noverhead.\n\ncg_sqlite and cg_psql are fast bash-builtins for SQLite and Postgresql with less overhead.\n\n**Status**:\nNeeds more testing.\n\n\n# Usage\n\n    db=/tmp/my_test_sqlite3.db\n    result=''\n    cg_sqlite  -$  -D \u003cdatabase file\u003e  'SQL_Statements;'; aa=(\"${RETVAL[@]}\")\n\n    echo \"Results: ${#aa[@]}    First: ${aa[0]:-}   Second: ${aa[1]:-}\"\n\n## Options\n\n    -D  \u003cdatabase file or connection info, respectively\u003e\n\n    -$                            Store query results in the variable 'RETVAL' instead of printing to stdout.\n\n    -d  $'\\t\\n'                   Delimiter of query result for columns (1st character) and rows (optional 2nd character)\n                                  Consider vertical bar as column separator: -d '|'\",\n\n    -l  \u003cMax number of results\u003e   Default value for stdout: Unlimited.  Default value for results stored in an array: 1024\n\n    -V                            Print version.  Can be used to check available of the builtin\n\n    -v                            Increase verbosity. Can be repeated.\n\n\n# Example\n\n\n    db=/tmp/my_test_sqlite3.db\n    cg_sqlite  -D $db  'CREATE TABLE IF NOT EXISTS tbl (id int,t TEXT);'\n    cg_sqlite  -D $db  \"INSERT INTO tbl(id,t) VALUES($RANDOM,'$(date)');\"\n    cg_sqlite  -D $db  'SELECT * FROM tbl;'  # Result to stdout\n\n    cg_sqlite  -D $db  -$  'SELECT * FROM tbl;'; array_variable=(\"${RETVAL[@]}\")\n    echo \"${array_variable[@]}\"\n\n\n\n## Benchmarks\n\nRun SQL_benchmark.sh without parameter for  instructions.\n\n10,000 simple SELECT queries - lower values are better:\n\n    /usr/bin/pgsql          811 seconds\n    /usr/bin/sqlite          59 seconds\n\n    cg_psql   bashbuiltin   1.3 seconds\n    cg_sqlite bashbuiltin   0.5 seconds\n\n\n\n\n\n\n\n\n# Compilation and Installation\n\nFirst [Install dependencies](./INSTALL_DEPENDENCIES.md)\n\nThe enclosed compile script generates shared object files with the ending *.so*.\n\n    compile_C.sh bashbuiltin_psql.c\n\nor\n\n    compile_C.sh bashbuiltin_sqlite.c\n\n\nBuiltins need to be loaded into the Bash instance with *enable*.  The following commands can be run in the\ncurrent interactive shell or can be placed at the top of a Bash script.\n\n    enable -f ~/compiled/bashbuiltin_sqlite.so   cg_sqlite\n\nor\n\n    enable -f ~/compiled/bashbuiltin_psql.so   cg_psql\n\n\nWhen they are loaded successfully, the *help* command will print the full documentation\n\n    help cg_psql\n\nor\n\n    help cg_sqlite\n\n\n\n# Limitations\n\n - Currently only one record of SELECT queries are stored in the variable *RETVAL*.\n   ARRAYS of multiple results has caused problems and is currently not yet supported\n\n - Other DBs like  MySQL and  DB2 are not (yet) supported. You can send a request-for-feature.\n\n# Related:\n  - coproc\n     + https://stackoverflow.com/questions/18726499/how-to-use-coproc-to-interact-with-another-command-driven-program\n     + https://www.michael-joost.de/bash_db.html\n  - https://github.com/Aloxaf/zsh-sqlite\n  - https://github.com/PietroFara/sqlite_lib.bash\n  - https://github.com/koffiebaard/bashql\n  - https://github.com/cjungmann/bash_sqlite\n  - https://github.com/axelhahn/bash_sqlite\n  - https://github.com/edean11/BashDB\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristophgil%2Fbash_builtin_sql_db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchristophgil%2Fbash_builtin_sql_db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristophgil%2Fbash_builtin_sql_db/lists"}