{"id":13705737,"url":"https://github.com/petere/plsh","last_synced_at":"2025-02-26T02:19:52.110Z","repository":{"id":47477644,"uuid":"3535411","full_name":"petere/plsh","owner":"petere","description":"PL/sh is a procedural language handler for PostgreSQL that allows you to write stored procedures in a shell of your choice.","archived":false,"fork":false,"pushed_at":"2024-07-26T15:03:21.000Z","size":78,"stargazers_count":170,"open_issues_count":12,"forks_count":21,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-02-18T23:08:25.471Z","etag":null,"topics":["language","postgresql","postgresql-extension","shell","trigger"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/petere.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS","contributing":null,"funding":null,"license":"COPYING","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":"2012-02-24T12:13:18.000Z","updated_at":"2025-01-28T02:47:39.000Z","dependencies_parsed_at":"2024-07-26T16:12:15.393Z","dependency_job_id":null,"html_url":"https://github.com/petere/plsh","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petere%2Fplsh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petere%2Fplsh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petere%2Fplsh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petere%2Fplsh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/petere","download_url":"https://codeload.github.com/petere/plsh/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240109566,"owners_count":19749171,"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":["language","postgresql","postgresql-extension","shell","trigger"],"created_at":"2024-08-02T22:00:47.016Z","updated_at":"2025-02-26T02:19:52.056Z","avatar_url":"https://github.com/petere.png","language":"C","readme":"PL/sh Procedural Language Handler for PostgreSQL\n================================================\n\nPL/sh is a procedural language handler for PostgreSQL that allows you\nto write stored procedures in a shell of your choice.  For example,\n\n    CREATE FUNCTION concat(text, text) RETURNS text AS '\n    #!/bin/sh\n    echo \"$1$2\"\n    ' LANGUAGE plsh;\n\nThe first line must be a `#!`-style line that indicates the shell to\nuse.  The rest of the function body will be executed by that shell in\na separate process.  The arguments are available as `$1`, `$2`, etc.,\nas usual.  (This is the shell's syntax. If your shell uses something\ndifferent then that's what you need to use.)  The return value will\nbecome what is printed to the standard output, with a newline\nstripped.  If nothing is printed, a null value is returned.  If\nanything is printed to the standard error, then the function aborts\nwith an error and the message is printed.  If the script does not exit\nwith status 0 then an error is raised as well.\n\nThe shell script can do anything you want, but you can't access the\ndatabase directly.  Trigger functions are also possible, but they\ncan't change the rows.  Needless to say, this language should not be\ndeclared as `TRUSTED`.\n\nThe distribution also contains a test suite in the directory `test/`,\nwhich contains a simplistic demonstration of the functionality.\n\nI'm interested if anyone is using this.\n\nPeter Eisentraut \u003cpeter@eisentraut.org\u003e\n\nDatabase Access\n---------------\n\nYou can't access the database directly from PL/sh through something\nlike SPI, but PL/sh sets up libpq environment variables so that you\ncan easily call `psql` back into the same database, for example\n\n    CREATE FUNCTION query (x int) RETURNS text\n    LANGUAGE plsh\n    AS $$\n    #!/bin/sh\n    psql -At -c \"select b from pbar where a = $1\"\n    $$;\n\nNote: The \"bin\" directory is prepended to the path, but only if the `PATH` environment variable is already set.\n\nTriggers\n--------\n\nIn a trigger procedure, trigger data is available to the script\nthrough environment variables (analogous to PL/pgSQL):\n\n* `PLSH_TG_NAME`: trigger name\n* `PLSH_TG_WHEN`: `BEFORE`, `INSTEAD OF`, or `AFTER`\n* `PLSH_TG_LEVEL`: `ROW` or `STATEMENT`\n* `PLSH_TG_OP`: `DELETE`, `INSERT`, `UPDATE`, or `TRUNCATE`\n* `PLSH_TG_TABLE_NAME`: name of the table the trigger is acting on\n* `PLSH_TG_TABLE_SCHEMA`: schema name of the table the trigger is acting on\n\nEvent Triggers\n--------------\n\nIn an event trigger procedure, the event trigger data is available to\nthe script through the following environment variables:\n\n* `PLSH_TG_EVENT`: event name\n* `PLSH_TG_TAG`: command tag\n\nInline Handler\n--------------\n\nPL/sh supports the `DO` command.  For example:\n\n    DO E'#!/bin/sh\\nrm -f /tmp/file' LANGUAGE plsh;\n\nInstallation\n------------\n\nYou need to have PostgreSQL 8.4 or later, and you need to have the\nserver include files installed.\n\nTo build and install PL/sh, use this procedure:\n\n    make\n    make install\n\nThe include files are found using the `pg_config` program that is\nincluded in the PostgreSQL installation.  To use a different\nPostgreSQL installation, point configure to a different `pg_config` like\nso:\n\n    make PG_CONFIG=/else/where/pg_config\n    make install PG_CONFIG=/else/where/pg_config\n\nNote that generally server-side modules such as this one have to be\nrecompiled for every major PostgreSQL version (that is, 8.4, 9.0,\n...).\n\nTo declare the language in a database, use the extension system with\nPostgreSQL version 9.1 or later.  Run\n\n    CREATE EXTENSION plsh;\n\ninside the database of choice.  To upgrade from a previous\ninstallation that doesn't use the extension system, use\n\n    CREATE EXTENSION plsh FROM unpackaged;\n\nUse `DROP EXTENSION` to remove it.\n\nWith versions prior to PostgreSQL 9.1, use\n\n    psql -d DBNAME -f .../share/contrib/plsh.sql\n\nwith a server running.  To drop it, use `droplang plsh`, or `DROP\nFUNCTION plsh_handler(); DROP LANGUAGE plsh;` if you want to do it\nmanually.\n\nTest suite\n----------\n\n[![Build Status](https://api.cirrus-ci.com/github/petere/plsh.svg)](https://cirrus-ci.com/github/petere/plsh)\n\nTo run the test suite, execute\n\n    make installcheck\n\nafter installation.\n","funding_links":[],"categories":["C"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpetere%2Fplsh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpetere%2Fplsh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpetere%2Fplsh/lists"}