0

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

PostgreSQL Version - 9.3

2
  • Unrelated, but: Postgres 9.3 is no longer supported you should plan an upgrade as soon as possible. Commented Jul 5, 2019 at 5: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. Commented Jul 5, 2019 at 5:15

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

5 Comments

I see, Strange requirement. I have changed my answer.
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.
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.
Thanks let me check PL/Java. Can you please provide some useful links. You can also answer on stackoverflow.com/questions/56896456/…
@a_horse_with_no_name has already provided that information there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.