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 1qhRZl-002eka-Vt for pgsql-sql@arkaria.postgresql.org; Sat, 16 Sep 2023 09:26:54 +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 1qhRZj-00A0tg-V4 for pgsql-sql@arkaria.postgresql.org; Sat, 16 Sep 2023 09:26:51 +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 1qhRZj-00A0tR-AL for pgsql-sql@lists.postgresql.org; Sat, 16 Sep 2023 09:26:51 +0000 Received: from mx0b-00520701.pphosted.com ([205.220.176.224]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qhRZa-004s0h-Vv for pgsql-sql@postgresql.org; Sat, 16 Sep 2023 09:26:49 +0000 Received: from pps.filterd (m0269119.ppops.net [127.0.0.1]) by mx0b-00520701.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38G5sXts011233 for ; Sat, 16 Sep 2023 05:26:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=moodys.com; h=from : to : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=mdydkim1; bh=stXKzBWasmJD/IS9HEto33aYXNBmscdUUTntQ7kp71s=; b=PD42y0VWyY8bb2Qqmv46LxEYCC97ms+NdyHds5s/hdmt2Ku5e1utAbPMevgwAHApa/m9 tvqygD7NkpVUcOxIFGU4ckRdXPneYLvK3WEdAgMOZVdHNr/Sq7/mqKiil/334hYJe5sG wuN8LsUBIqKkEaxRzEyWdb0+nA7NZKXpfH+aeDWhhjb3xwuBj2NYn+AheRa6M0LsJjn6 k1kc/i3cV2ejHPiuDviGho2OIwOsxh36IBEZ7W3op/FgDvmOU2+W823/88bIyRZW70qI +tOgFV2CtdSXmCKmIGAFwW8dVUUJZmmwYSM+0b7BSF6wKJtUiyEVRaFjHzr2ATocoVbT eg== Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam04lp2173.outbound.protection.outlook.com [104.47.73.173]) by mx0b-00520701.pphosted.com (PPS) with ESMTPS id 3t55vx8jbg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 16 Sep 2023 05:26:41 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Uv7v9Wl0+BEJSr6q2Lj29eWS1pQUxRFPz2ujhI+wD0jqO/3AN6QKiANfXEDkuvUo0omSac8W/axrvxArhc1WEkDspyBmx6zkxE24vmkd2O0loI3vP1cg+r4TSgu5Mh2ZVjyFQrACLvH6HnxIxhql4FOQ/nocSas24DZmrzE5pJBMWV3NTM9IWw6imcm/gLNCHnnPJj+q4/iB5+rlxTwTlZBuMnoGrDhJzm/R/pbNLNELJuNL8QElIzJOb+OFMr+N5ANchMGwiYk6LAwdX4eR/XMHzbv0HiJk+sxFgO+2JowgcYvv01YNtThBCtlKYZ3vx+hyvPZiToegA8JAKtzsxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ChXD5ygmwvsgae05QQxqB5PaG4SQuAirgcwnrgNdNNM=; b=j/0pCEL4hCqTg/1rEH2G86YrRNS6j8tq0duAhs5bpUjtMb6a3oLco+5wR48iJoWJ+0O8wN4Y07AtSUy0iGRwsvDWNEdAp688EK97OfdQU3Es/NdwpjuyI9KXaFY0dGGO2QITq6W/dbNytu8P6PlxaCcTRRVdfccaBrW/Pt/Zvf0NtiQMgEMnM18qlpXzeznvsC9LISU4AQTHwVpsOygBlN9agxChN3J9Rv9HGy0mFjkKPkcBFbez7PmbSY8ikrDyVh1BpqlJt6+T7iFFF8AtPUiiO/2UShoU+rUFKM9PY7zeVKtCEE5f9Krx9exTgDksAdbnfij/Wfa0IgXAeQg+6Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=moodys.com; dmarc=pass action=none header.from=moodys.com; dkim=pass header.d=moodys.com; arc=none Received: from MN2PR20MB2735.namprd20.prod.outlook.com (2603:10b6:208:f6::11) by BLAPR20MB3748.namprd20.prod.outlook.com (2603:10b6:208:330::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.24; Sat, 16 Sep 2023 09:26:30 +0000 Received: from MN2PR20MB2735.namprd20.prod.outlook.com ([fe80::68c3:b584:9933:775c]) by MN2PR20MB2735.namprd20.prod.outlook.com ([fe80::68c3:b584:9933:775c%4]) with mapi id 15.20.6792.023; Sat, 16 Sep 2023 09:26:29 +0000 From: "Jean-Marc Voillequin (MA)" To: "pgsql-sql@postgresql.org" Subject: no_data_found oracle vs pg Thread-Topic: no_data_found oracle vs pg Thread-Index: Adnoe0OoLXOaVG7cSxyH3NXNcBCAcQ== Date: Sat, 16 Sep 2023 09:26:29 +0000 Message-ID: Accept-Language: fr-FR, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MN2PR20MB2735:EE_|BLAPR20MB3748:EE_ x-ms-office365-filtering-correlation-id: 35ca67a1-f28b-4008-58ba-08dbb6970239 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: gUUQ3KEaId30zWFFbS0y0eXrGOaEkHdOvTzueC8NlVSwmnx1Yvk05RPUFeYDhnu9C/UTjU4zVqKs+lq7yogN6OuxwsxUNSRKx6mbDJhGPlgQ+WpFwBSd+mbcP6tH03AFLTKI81kCB8aEIauZpmNtZiDNKICjqrQj3w5WR1BsL2tPWqPDhahyASZN/ctaU0+rPT4ii+UKLIQ8PPdY9c6DQ5PtssKMDDz9tmbsIDbSYxVTN+3H58cvqRIMxZSgjwXb3PXtdiUDASQGlgk0OtTCfz9SNcua1dDZyEU9Q62JcuSXLxyagLJm3ptGRHtFb2YlkbetQsIlg6gDEsvCWNPgJT6xPauroSLzJa+Wk5FNyfPkE8fSEpX3mEfHyLFM7BRTJsnHfwk0PRiZI08QBWQTYzBrJIyvMafZNBpbX5Ca4tlSDve53Wl95sZyhCN/TdFEc0t+B8xFDxNRELbMtCsGHkFQ0dafJPa3aRdTraK0rSAatVMrifxarFVozkYD3XHWt6QgntcOQv1Ha3U0INPFExXCJLS5P0jMqdNNqjXpiQORzC+mzEN01nPhoYMQUCRiSYGcxhThgcbP7kpelDYOkHc+Eg+Xmj2nEBYZdtSL/FwZyWkaA6zg+zajvJNSLSvb x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR20MB2735.namprd20.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(136003)(366004)(396003)(376002)(451199024)(186009)(1800799009)(122000001)(38100700002)(38070700005)(86362001)(55016003)(33656002)(66899024)(6506007)(7696005)(478600001)(5660300002)(52536014)(66946007)(66556008)(66476007)(66446008)(64756008)(76116006)(2906002)(71200400001)(8936002)(8676002)(9686003)(83380400001)(41300700001)(6916009)(316002)(26005);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?qAf4pcZY+WphHaXXksTipeAcxQyqFWk++cjQnfdjgX+TO0q2q+lHo9TtVtMV?= =?us-asc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9ZOnU5pkh2eCqpYDOHU5dp8X?= =?us-ascii?Q?+GBgT/b3qCdHz0ZExmt1lNHGdHvNwRMX6BSqhFGU7Ej1uhPI28RQJXFhwicR?= =?us-ascii?Q?rEIDGZPveU0vPYEZFlCrK283b6Pv/2lrwbs7b55LyKPl7hqXcv4jhbbFH1EA?= =?us-ascii?Q?zKRJyy/0iLFbqNBvQwe1Gbx5f4Hbts1kThnr9Ok6dVh5Kyt4JK/ZiSmkryjE?= =?us-ascii?Q?0AmZe7xu4Gyfn95tLivQSRGZb6Zq8GnPfsRM376dWhXSBVFtUMVRSsMhIES7?= =?us-ascii?Q?boty3QsZPcBmiCriV3rQKwDiBwT5xhjmDikMlhUFkSxMRIZeEA6OZx/Zcxdc?= =?us-ascii?Q?UrXQQPqBfpt+kcKfLUI3AlWCDQuFNB+Ok+3n+guVSuWDbmB91JnJiIVE5Va7?= =?us-ascii?Q?h4G4NSxvgw4iJ4rRCEJh3QfUbrnhdpkIKy1o3TDNQHnFyOugPLMvVTyw2CxL?= =?us-ascii?Q?bgZx5Mw6F/EA6uWQbVslbZJnrMvo8f8BczFwsC6thmziwFhhDxnbqZ8IHND/?= =?us-ascii?Q?qPmw4YrfZDFgIpg+T1aToXEbwFqGYQ8srO5ensI5WY8Rd+HHqXGnc3Ur4Gfz?= =?us-ascii?Q?I2toiu2/yaI+g45vkk308O80Wv1+gHGMgImGZiarfWRCvInVv64mCvtiOIj+?= =?us-ascii?Q?10bdh1SUPfEtXap0RzRWPhzAzDq70ngL467DgT2z?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: moodys.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN2PR20MB2735.namprd20.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 35ca67a1-f28b-4008-58ba-08dbb6970239 X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Sep 2023 09:26:29.6120 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 1061a8b8-b1ee-4249-bb84-9a2cd2792fae X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: tsq6ITHOT24QVTdIt/TAoudecuQSWjVYFfdDgJ05t69rR5YaDhB63snIZ1cGD39/rr16FWZruBvhGwotBFGLzg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR20MB3748 X-Proofpoint-GUID: RfE3mMYgXkxIvxopnXgYOZh_cKQM2DaM X-Proofpoint-ORIG-GUID: RfE3mMYgXkxIvxopnXgYOZh_cKQM2DaM X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-15_20,2023-09-15_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 bulkscore=0 mlxlogscore=346 malwarescore=0 phishscore=0 spamscore=0 mlxscore=0 clxscore=1011 lowpriorityscore=0 adultscore=0 impostorscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309160081 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello everyone, On Oracle, a no_data_found exception is raised from pl/sql but not from sql= (it returns null). It's well known. Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production SQL> create or replace function hello return char is 2 c char; 3 begin 4 select 'a' into c from dual where 1=3D2; 5 return c; 6 end; 7 / Function created. SQL> select coalesce(hello(),'') from dual; COALESCE(HELLO(),'') ---------------------------------------------------------------------------= ----- SQL> declare 2 res char; 3 begin 4 res:=3Dhello(); 5 end; 6 / declare * ERROR at line 1: ORA-01403: no data found ORA-06512: at "JM.HELLO", line 4 ORA-06512: at line 4 On PG, with the strict keyword, we get: psql (15.2) Type "help" for help. JM=3D> create or replace function hello_strict() returns char language plpg= sql as $function$ JM$> declare JM$> c char; JM$> begin JM$> select 'a' into strict c where 1=3D2; JM$> return c; JM$> end;$function$; CREATE FUNCTION JM=3D> select coalesce(hello_strict(),''); ERROR: query returned no rows CONTEXT: PL/pgSQL function hello_strict() line 5 at SQL statement JM=3D> do $$declare JM$> res char; JM$> begin JM$> res:=3Dhello_strict(); JM$> end$$; ERROR: query returned no rows CONTEXT: PL/pgSQL function hello_strict() line 5 at SQL statement PL/pgSQL function inline_code_block line 4 at assignment And without the strict keyword: JM=3D> create or replace function hello_not_strict() returns char language = plpgsql as $function$ JM$> declare JM$> c char; JM$> begin JM$> select 'a' into c where 1=3D2; JM$> return c; JM$> end;$function$; CREATE FUNCTION JM=3D> select coalesce(hello_not_strict(),''); coalesce ---------- (1 row) JM=3D> do $$declare JM$> res char; JM$> begin JM$> res:=3Dhello_not_strict(); JM$> end$$; DO JM=3D> I have tons of functions to migrate from Oracle to PG. They are both called= from SQL or PL/SQL. I would like to avoid to create two functions (_strict and _not_strict). A kind of proxy function that is lazy to evaluate its argument would be hel= pful: select do_not_raise_no_data_found(hello_strict()); Or maybe a parameter to set just prior to exec sql. set do_not_raise_no_data_found_in_sql=3Dtrue; select hello_strict(); Or something else. Any good idea is welcome! I've been able to transpose to PG all Oracle specific features ((+) left jo= in operator, connect by, packages, etc).=20 It was a big challenge almost successful. But I cannot figure out how to solve this strict/not strict difference in a= smart way. This is my last blocking point. It makes me crazy! Thanks & Regards ---------------------------------------------------------------------- Moody's monitors email communications through its networks for regulatory c= ompliance purposes and to protect its customers, employees and business and= where allowed to do so by applicable law. The information contained in thi= s e-mail message, and any attachment thereto, is confidential and may not b= e disclosed without our express permission. If you are not the intended rec= ipient or an employee or agent responsible for delivering this message to t= he intended recipient, you are hereby notified that you have received this = message in error and that any review, dissemination, distribution or copyin= g of this message, or any attachment thereto, in whole or in part, is stric= tly prohibited. If you have received this message in error, please immediat= ely notify us by telephone, fax or e-mail and delete the message and all of= its attachments. Every effort is made to keep our network free from viruse= s. You should, however, review this e-mail message, as well as any attachme= nt thereto, for viruses. We take no responsibility and have no liability fo= r any computer virus which may be transferred via this e-mail message.