pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ц <pfunk@mail.ru>
To: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: SQL state: 42601. Execption handling. 
Date: Tue, 07 Jun 2022 16:11:29 +0300
Message-ID: <1654607489.576623819@f729.i.mail.ru> (raw)


Community, is that behavior is  explainable ?
 
create   or   replace   function  dbo.func(result  out   int )  as  $$ begin  result =  1 ;  end ; $$  language  plpgsql; 

-- 1 -- 
do  $$ 
declare
v_result  int ; 
begin  
   select  p.result  from  dbo.func(d) p  into  v_result; 
exception   when  SQLSTATE  '42601'   then
     raise   '42601' ;
   when   others   then  
     raise   'others' ; 
end ;
$$
 
--Exception is handled. This is OK.
ERROR:   others
CONTEXT:  PL/pgSQL  function  inline_code_block line  9   at   RAISE
********** Error **********
ERROR:  others
SQL  state: P0001
Context: PL/pgSQL  function  inline_code_block line  9   at   RAISE

-- 2 -- 
do  $$ 
begin  
   select  p.result  from  dbo.func() p  into  v_result; 
exception   when  SQLSTATE  '42601'   then
     raise   '42601' ;
   when   others   then  
     raise   'others' ; 
end ;
$$
 
--Exception is not handled. This is the question.
ERROR:   "v_result"   is   not  a known variable
LINE  3 :    select  p.result  from  dbo.func() p  into  v_result;
********** Error **********
ERROR:  "v_result"   is   not  a known variable 
SQL  state:  42601
Character :  57
 
I suppose the reason of such behavior in different steps of code parsing, but can`t find any discussions or topics in documentation.
Сould someone clarify the situation for sure?

view thread (4+ messages)  latest in thread

Message-ID: <1654607489.576623819@f729.i.mail.ru>
Permalink:  ../1654607489.576623819@f729.i.mail.ru/
Also on:    postgresql.org/message-id/1654607489.576623819@f729.i.mail.ru

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: pfunk@mail.ru
  Subject: Re: SQL state: 42601. Execption handling.
  In-Reply-To: <1654607489.576623819@f729.i.mail.ru>
  References: <1654607489.576623819@f729.i.mail.ru>

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

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