pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #14861: Handle syntax_error
2+ messages / 2 participants
[nested] [flat]

* BUG #14861: Handle syntax_error
@ 2017-10-18 15:32  andrey_shvidky@hotmail.com
  0 siblings, 1 reply; 2+ messages in thread

From: andrey_shvidky@hotmail.com @ 2017-10-18 15:32 UTC (permalink / raw)
  To: pgsql-bugs; +Cc: andrey_shvidky@hotmail.com

The following bug has been logged on the website:

Bug reference:      14861
Logged by:          Andrey Shvidky
Email address:      andrey_shvidky@hotmail.com
PostgreSQL version: 9.6.5
Operating system:   Windows 7 x64
Description:        

/*
Faced with such a unfairness.
I have a do block or function with error handling block.
In case when error type is 42601 (syntax_error) I can't get correct error
context.
The error context contains information about do block or function itself,
but not about last executed instruction.
In the folowing example, if I remove error handling I will happily have such
a message:

ERROR: subquery must return only one column
LINE 1: SELECT (select id, val1 from aaa)
 
But in case when error handling presents I have only sad:

message_text = subquery must return only one column
pg_exception_context = PL/pgSQL function inline_code_block line 9 at
assignment
pg_exception_detail =

Where information about "SELECT (select id, val1 from aaa)" hided?
 
Repro script:
*/

create temp table aaa (id int, val1 text);

do language plpgsql $$
declare
	error_message			text;
	error_detailed_message	text;
	error_context			text;
	arr_test				aaa[];
begin
	--arr_test = (select row(id, val1) from aaa);		-- No error, correct call
	arr_test = (select id, val1 from aaa);			-- Error 42601 syntax_error 
exception
	--when syntax_error then
	when others then
		get stacked diagnostics
			error_message = message_text
            ,error_context = pg_exception_context
			,error_detailed_message = pg_exception_detail;

		raise notice 'message_text = %', error_message;
		raise notice 'pg_exception_context = %', error_context;
        raise notice 'pg_exception_detail = %', error_detailed_message;
end
$$;

drop table if exists aaa;


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #14861: Handle syntax_error
@ 2017-10-19 19:01  Pavel Stehule <pavel.stehule@gmail.com>
  parent: andrey_shvidky@hotmail.com
  0 siblings, 0 replies; 2+ messages in thread

From: Pavel Stehule @ 2017-10-19 19:01 UTC (permalink / raw)
  To: andrey_shvidky@hotmail.com; +Cc: pgsql-bugs

Hi

2017-10-18 17:32 GMT+02:00 <andrey_shvidky@hotmail.com>:

> The following bug has been logged on the website:
>
> Bug reference:      14861
> Logged by:          Andrey Shvidky
> Email address:      andrey_shvidky@hotmail.com
> PostgreSQL version: 9.6.5
> Operating system:   Windows 7 x64
> Description:
>
> /*
> Faced with such a unfairness.
> I have a do block or function with error handling block.
> In case when error type is 42601 (syntax_error) I can't get correct error
> context.
> The error context contains information about do block or function itself,
> but not about last executed instruction.
> In the folowing example, if I remove error handling I will happily have
> such
> a message:
>
> ERROR: subquery must return only one column
> LINE 1: SELECT (select id, val1 from aaa)
>
> But in case when error handling presents I have only sad:
>
> message_text = subquery must return only one column
> pg_exception_context = PL/pgSQL function inline_code_block line 9 at
> assignment
> pg_exception_detail =
>
> Where information about "SELECT (select id, val1 from aaa)" hided?
>
> Repro script:
> */
>
> create temp table aaa (id int, val1 text);
>
> do language plpgsql $$
> declare
>         error_message                   text;
>         error_detailed_message  text;
>         error_context                   text;
>         arr_test                                aaa[];
> begin
>         --arr_test = (select row(id, val1) from aaa);           -- No
> error, correct call
>         arr_test = (select id, val1 from aaa);                  -- Error
> 42601 syntax_error
> exception
>         --when syntax_error then
>         when others then
>                 get stacked diagnostics
>                         error_message = message_text
>             ,error_context = pg_exception_context
>                         ,error_detailed_message = pg_exception_detail;
>
>                 raise notice 'message_text = %', error_message;
>                 raise notice 'pg_exception_context = %', error_context;
>         raise notice 'pg_exception_detail = %', error_detailed_message;
> end
> $$;
>
> drop table if exists aaa;
>
>
Currently GET STACKED DIAGNOSTICS doesn't publish a "internalquery" field
from ErrorData structure. So you cannot to print it. Probably it should be
short patch, but maybe long discussion how to take this feature.

Maybe plpgsql_check https://github.com/okbob/plpgsql_check can be good tool
for you.

Regards

Pavel


>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs
>

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2017-10-19 19:01 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-10-18 15:32 BUG #14861: Handle syntax_error andrey_shvidky@hotmail.com
2017-10-19 19:01 ` Pavel Stehule <pavel.stehule@gmail.com>

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