Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mniCP-0005ra-7u for pgsql-general@arkaria.postgresql.org; Thu, 18 Nov 2021 14:15:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mniCN-0002TW-PS for pgsql-general@arkaria.postgresql.org; Thu, 18 Nov 2021 14:15:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mniCN-0002Rx-3A for pgsql-general@lists.postgresql.org; Thu, 18 Nov 2021 14:15:35 +0000 Received: from resqmta-h1p-028595.sys.comcast.net ([2001:558:fd02:2446::3]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mniCJ-00042V-9G for pgsql-general@postgresql.org; Thu, 18 Nov 2021 14:15:34 +0000 Received: from resomta-ch2-17v.sys.comcast.net ([69.252.207.113]) by resqmta-h1p-028595.sys.comcast.net with ESMTP id nhbMmBfzPxqgxniCBmGLa0; Thu, 18 Nov 2021 14:15:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=20190202a; t=1637244923; bh=MaYQOaO0S8P1noswY9RsbbqaXiBk7p5qFMd+T+7LfKg=; h=Received:Received:Date:From:To:Message-ID:Subject:MIME-Version: Content-Type; b=anh4K61wiqG6JAcZWy8IycZCyTlgA3/xUZqSCje4Iaqy3elbWUF7+Cxn3Voil0l1R XdVmdG58Qh7rOofRQWiCs+CPbG9nDchFiNdwm0qICLUmsPBMZpZcw4I7bV/xRdeCvR vJwAxtLAqxGd/Kll8160mmqsVo6G9rFzfLvRc3i95LPduQ0TZNSsu/dhfk15luVnz8 k140jJyLZq7k41P7jt3CgIIm1x/PiilZDXfhdse7wT3oYSs/KvX7mVCewMaGtj6nSN SpXUDnkRmcyo7xhWHIvoTpkK0E8hCpVIQUWZ7GtF2kI44JW3u5om8V7r5ee+lfLXdM 3+1+K5+kPzXtg== Received: from oxapp-ch2f-13o.email.comcast.net ([96.117.82.148]) by resomta-ch2-17v.sys.comcast.net with ESMTPS id niC1mo3j9n49aniC1mjNuX; Thu, 18 Nov 2021 14:15:13 +0000 X-Xfinity-VAAS: gggruggvucftvghtrhhoucdtuddrgedvuddrfeeigdehkecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucevohhmtggrshhtqdftvghsihdpqfgfvfdppffquffrtefokffrnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpeffhffvkfgjfhfugggtrfgkofhisegrtdgssgertdejnecuhfhrohhmpeffteggkfffucftqffvjfcuoegruggrphhtrhhonhestghomhgtrghsthdrnhgvtheqnecuggftrfgrthhtvghrnhephfefheduheelueevjeefgedufefgjeegffetiedtgfdtueduheelvdegleektdevnecukfhppeeliedruddujedrkedvrddugeekpddviedtudemudeludemkeegtddtmeguvdgrtdemrgdumeekjeegjeemuggstgemugdvugegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehhvghlohepohigrghpphdqtghhvdhfqddufehordgvmhgrihhlrdgtohhmtggrshhtrdhnvghtpdhinhgvthepleeirdduudejrdekvddrudegkedpmhgrihhlfhhrohhmpegruggrphhtrhhonhestghomhgtrghsthdrnhgvthdprhgtphhtthhopehpghhsqhhlqdhgvghnvghrrghlsehpohhsthhgrhgvshhqlhdrohhrgh X-Xfinity-VMeta: sc=-100.00;st=legit Date: Thu, 18 Nov 2021 09:15:13 -0500 (EST) From: DAVID ROTH To: Postgres General Message-ID: <1653563957.563818.1637244913291@connect.xfinity.com> In-Reply-To: References: Subject: General Performance Question MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_563817_526422537.1637244913258" X-Priority: 3 Importance: Normal X-Mailer: Open-Xchange Mailer v7.10.5-Rev21 X-Originating-IP: 2601:191:8400:d2a0:a1:8747:dbc:d2d4 X-Originating-Client: open-xchange-appsuite List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------=_Part_563817_526422537.1637244913258 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit I am working on a large Oracle to Postgres migration. The existing code frequently constructs a string and then uses Oracle's "EXECUTE IMMEDIATE" to run it. "EXECUTE" has the same functionality in Postgres. For example: CREATE or REPLACE FUNCTION djr_foo_fnc (p_emp_no IN number) RETURN VARCHAR2 AS v_sql VARCHAR2(1000); v_name VARCHAR2(30); BEGIN v_sql := 'SELECT name FROM employees'; v_sql := v_sql ||' WHERE employee_number = '||p_emp_no; EXECUTE IMMEDIATE v_sql INTO v_name; RETURN v_name; END; / CREATE or REPLACE FUNCTION djr_foo_fnc (p_emp_no IN number) RETURN VARCHAR2 AS v_name VARCHAR2(30); BEGIN SELECT name INTO v_name FROM employees WHERE employee_number = p_emp_no; RETURN v_name; END; / These are oversimplified samples of some very complex queries I need to migrate. How does the Postgres optimizer handle these 2 formats? Which format is likely to perform better? Thanks Dave ------=_Part_563817_526422537.1637244913258 MIME-Version: 1.0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit
I am working on a large Oracle to Postgres migration.
The existing code frequently constructs a string and then uses Oracle's "EXECUTE IMMEDIATE" to run it.
"EXECUTE" has the same functionality in Postgres.

For example:
CREATE or REPLACE FUNCTION djr_foo_fnc (p_emp_no IN number)
RETURN VARCHAR2
AS
v_sql VARCHAR2(1000);
v_name VARCHAR2(30);
BEGIN
v_sql :=            'SELECT name FROM employees';
v_sql := v_sql ||' WHERE employee_number = '||p_emp_no;
EXECUTE IMMEDIATE v_sql INTO v_name;
RETURN v_name;
END;
/

CREATE or REPLACE FUNCTION djr_foo_fnc (p_emp_no IN number)
RETURN VARCHAR2
AS
v_name VARCHAR2(30);
BEGIN
SELECT name INTO v_name FROM employees
WHERE employee_number = p_emp_no;
RETURN v_name;
END;
/

These are oversimplified samples of some very complex queries I need to migrate.

How does the Postgres optimizer handle these 2 formats?
Which format is likely to perform better?
Thanks
Dave
------=_Part_563817_526422537.1637244913258--