Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sl7Cf-005JKX-2F for pgsql-novice@arkaria.postgresql.org; Mon, 02 Sep 2024 13:34:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sl7Ce-00EOsG-5e for pgsql-novice@arkaria.postgresql.org; Mon, 02 Sep 2024 13:34:44 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sl7Cd-00EOlq-Mb for pgsql-novice@lists.postgresql.org; Mon, 02 Sep 2024 13:34:44 +0000 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sl7Cb-000IIo-3L for pgsql-novice@lists.postgresql.org; Mon, 02 Sep 2024 13:34:42 +0000 Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-a8679f534c3so439375366b.0 for ; Mon, 02 Sep 2024 06:34:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20230601.gappssmtp.com; s=20230601; t=1725284079; x=1725888879; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=venAZeqMmXnfdVG6H0zEIf+fAG2LluOIQM0JY5eH0U4=; b=PkdLa2UE/v4OZkLfCfpciGYmF7FQCrhUXH+Qn0Esl6+YGimWjnghWZhm6237RgntQl McqcSeCaYPVyVCSDw05aYGqQwJjhYTKVKdmzagbrPW96GLmlP4Oq1h5bAiOWCE2lCqDn wPkC54hSRPO8e4f9aviOcraqrtfh1DsiIUbYaiQiR3UyBQhWRX85BiTK37nDeqJSdgdC 11dd/H9FqHVvM2Y+aGmKyrkY40ULiYo5J3SgpDFpI76j4ucTiTtQR+BtTyt8gPaoNLM6 TRXdnDJcvszEdfjBVIWLRHuBNkYyPKmKnpJv2r69zCw4XURlS4eePImUo26LUkzguzPe FcYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725284079; x=1725888879; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=venAZeqMmXnfdVG6H0zEIf+fAG2LluOIQM0JY5eH0U4=; b=Dfv2WE0x0QaYAhZhQ+8O73i9xHwqOFXHxg1E/OMV915K9aNmgbC+TF8W1F/uPuTISw X8D3H6rwNC25AlTR01HwX/9fQEinBzxsNWVfo9IIgkFIuUPJjcKMoMUqL85hFIF7EX4L tKAwEkXk/lmfDJuWAqv+lr9ZqCPkGJHQSX8Uqod/V0TliHLS0sFqfMB11XhtETdRvUor /1I9bxhj6YhMbNwAl7eWsMgJmLaB/Kt8Sk60DgbMokzAWs/UTG7zrY8syQz1aBEcOu+v NIK8CDFzK8ZP/XFhcueekgC8aOHkH23LMV6Al5h7qgHHrNv53o6aXATLNcOwv9FFIi1B ue0g== X-Forwarded-Encrypted: i=1; AJvYcCVSETUAVIs/SPlX9vfl7kcwKlJ+jnVxSKFfWY93icfEMMoYZbgLCZXVmb+e4JRTR/m5Td2tzJKrY/Jtm1g=@lists.postgresql.org X-Gm-Message-State: AOJu0YwY2/QGuS7B+YY+SDsUGWv+SAuIGslZFFs5Ipu5H5T8+T3UiqCd d0jAi91kN6tGtqEqm7LTTg6B0oGLadgNhRqf9+EXSGlc2gOk9IlPGmdDO1SpsbXJYRMyBXsXXeG O X-Google-Smtp-Source: AGHT+IGf10QqnM8bBAZJxhNDFpZF8RbOgXu3Yzv6PT/K82bmaPV5vldbuKObISZdzpRHk5OCBM8fQg== X-Received: by 2002:a17:907:3ea4:b0:a86:94e2:2a47 with SMTP id a640c23a62f3a-a89d8781b18mr474093466b.15.1725284078725; Mon, 02 Sep 2024 06:34:38 -0700 (PDT) Received: from dynamic-pd01.res.v6.highway.a1.net ([2001:871:5e:53f4:c624:8ff4:8180:8ef6]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a898900f29csm558795966b.64.2024.09.02.06.34.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 06:34:38 -0700 (PDT) Message-ID: <667ba77c9d834363c2d23dab61ab2f003f68be8c.camel@cybertec.at> Subject: Re: Calling oracle function from PostgreSQL From: Laurenz Albe To: Shweta Rahate , pgsql-novice@lists.postgresql.org Date: Mon, 02 Sep 2024 15:34:37 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.4 (3.52.4-1.fc40) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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. >=20 > The oracle function should take the input from Postgres db and returns th= e output. > Please suggest a way to achieve=C2=A0this.=C2=A0 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 :=3D 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 =3D 12 RETURNING outp; That's ugly, but perhaps it is good enough as a workaround. Yours, Laurenz Albe