0

I need to run a shell script in PostgreSQL and get output in a variable.

PostgreSQL Version - 9.3

Tajinder
  • 2,248
  • 4
  • 33
  • 54
  • Unrelated, but: Postgres 9.3 is [no longer supported](https://www.postgresql.org/support/versioning/) you should plan an upgrade as soon as possible. –  Jul 05 '19 at 05:01
  • @a_horse_with_no_name Thanks, you are right about Postgres 9.3. You can also answer for later database version. Actually, I want to run a java function from PostgresSQL, I have executed the code in a shell script. Now, trying to run shell script from PostgreSQL. In case this approach is wrong, please suggest. – Tajinder Jul 05 '19 at 05:15

1 Answers1

1

To run a shell script inside the database, you'd have to install the PL/sh procedural language.

I am not sure what you mean by a “variable” inside a database, but a function written in PL/sh can be used just like any other function.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
  • I see, Strange requirement. I have changed my answer. – Laurenz Albe Jul 05 '19 at 05:39
  • Thanks, My actual requirement to run a java function from PostgresSQL, I have executed the java code in a shell script. Now, trying to run shell script from PostgreSQL. In case this approach is wrong, please suggest. `Variable` is just a text variable defined in postgres function. – Tajinder Jul 05 '19 at 05:43
  • Yes, that approach is deeply wrong because it is overly complicated. If you *really* need to run Java code inside the database, you'd better use PL/Java. – Laurenz Albe Jul 05 '19 at 05:48
  • Thanks let me check PL/Java. Can you please provide some useful links. You can also answer on https://stackoverflow.com/questions/56896456/how-to-run-java-function-from-postgresql – Tajinder Jul 05 '19 at 05:52
  • @a_horse_with_no_name has already provided that information there. – Laurenz Albe Jul 05 '19 at 07:03