public inbox for [email protected]  
help / color / mirror / Atom feed
From: Laurenz Albe <[email protected]>
To: Shweta Rahate <[email protected]>
To: [email protected]
Subject: Re: Calling oracle function from PostgreSQL
Date: Mon, 02 Sep 2024 15:34:37 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAPuJPo5GgMXnwtdOERwHgrEgthqyX+iO0GL6Mv7qCw7uOz6T8g@mail.gmail.com>
References: <CAPuJPo5GgMXnwtdOERwHgrEgthqyX+iO0GL6Mv7qCw7uOz6T8g@mail.gmail.com>

On Fri, 2024-08-30 at 12:38 +0530, Shweta Rahate wrote:
> In my application there is a requirement to call the oracle function from PostgreSQL db.
> 
> The oracle function should take the input from Postgres db and returns the output.
> Please suggest a way to achieve this. 

There is no direct way to do this via oracle_fdw.

There are, however, a couple of hacks to do that; see the following example:

The Oracle function:

  CREATE OR REPLACE FUNCTION double(n NUMBER) RETURN NUMBER AS
  BEGIN
     RETURN n * 2;
  END;
  /

Then I can define an Oracle table with a single row and a trigger on it:

  CREATE TABLE call_double(inp NUMBER, outp NUMBER);

  INSERT INTO call_double VALUES (1, 1);

  COMMIT;

  CREATE TRIGGER double_trig BEFORE UPDATE ON call_double FOR EACH ROW
  BEGIN
     :NEW.outp := double(:NEW.inp);
  END;
  /

Now I can define a foreign table as follows:

  CREATE FOREIGN TABLE call_double(
     inp numeric OPTIONS (key 'true'),
     outp numeric)
  SERVER oracle OPTIONS (table 'CALL_DOUBLE');

And then the following UPDATE calls the function and returns the result:

  UPDATE call_double SET inp = 12 RETURNING outp;

That's ugly, but perhaps it is good enough as a workaround.

Yours,
Laurenz Albe





reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Calling oracle function from PostgreSQL
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox