pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #17099: Problem with EXECUTE and JSON
3+ messages / 3 participants
[nested] [flat]

* BUG #17099: Problem with EXECUTE and JSON
@ 2021-07-11 12:40  PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 2 replies; 3+ messages in thread

From: PG Bug reporting form @ 2021-07-11 12:40 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: ineron@icloud.com

The following bug has been logged on the website:

Bug reference:      17099
Logged by:          Eugene Ilushin
Email address:      ineron@icloud.com
PostgreSQL version: 11.7
Operating system:   centos-release-7-6.1810.2.el7.centos.x86_64
Description:        

DO $$
DECLARE
	_res jsonb;
BEGIN
	--EXECUTE
$sql$select(json_build_object('name','name','query','query','params','params','type','type')->>'name')
$sql$ into _res; -- do not work
	--EXECUTE ($sql$select ('{"name":"34534534"}'::jsonb)->>'name'$sql$) into
_res; -- work
	EXECUTE ($sql$select ('{"name":"ewrewfsf"}'::jsonb)->>'name'$sql$) into
_res; -- do not work
	raise notice '%',_res;
END$$;
Hi !
Why i get an error if sends text but not error if send digits ?
ERROR:  invalid input syntax for type json
DETAIL:  Token "ewrewfsf" is invalid.
CONTEXT:  JSON data, line 1: ewrewfsf
PL/pgSQL function inline_code_block line 7 at EXECUTE
SQL state: 22P02



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

* Re: BUG #17099: Problem with EXECUTE and JSON
@ 2021-07-11 13:48  Евгений Илюшин <ineron@icloud.com>
  parent: PG Bug reporting form <noreply@postgresql.org>
  1 sibling, 0 replies; 3+ messages in thread

From: Евгений Илюшин @ 2021-07-11 13:48 UTC (permalink / raw)
  To: ineron@icloud.com; pgsql-bugs@lists.postgresql.org

I figured it out, my mistake!
Sorry !!!


> 11 июля 2021 г., в 14:40, PG Bug reporting form <noreply@postgresql.org> написал(а):
> 
> The following bug has been logged on the website:
> 
> Bug reference:      17099
> Logged by:          Eugene Ilushin
> Email address:      ineron@icloud.com
> PostgreSQL version: 11.7
> Operating system:   centos-release-7-6.1810.2.el7.centos.x86_64
> Description:        
> 
> DO $$
> DECLARE
> 	_res jsonb;
> BEGIN
> 	--EXECUTE
> $sql$select(json_build_object('name','name','query','query','params','params','type','type')->>'name')
> $sql$ into _res; -- do not work
> 	--EXECUTE ($sql$select ('{"name":"34534534"}'::jsonb)->>'name'$sql$) into
> _res; -- work
> 	EXECUTE ($sql$select ('{"name":"ewrewfsf"}'::jsonb)->>'name'$sql$) into
> _res; -- do not work
> 	raise notice '%',_res;
> END$$;
> Hi !
> Why i get an error if sends text but not error if send digits ?
> ERROR:  invalid input syntax for type json
> DETAIL:  Token "ewrewfsf" is invalid.
> CONTEXT:  JSON data, line 1: ewrewfsf
> PL/pgSQL function inline_code_block line 7 at EXECUTE
> SQL state: 22P02
> 






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

* Re: BUG #17099: Problem with EXECUTE and JSON
@ 2021-07-12 08:06  Sergei Kornilov <sk@zsrv.org>
  parent: PG Bug reporting form <noreply@postgresql.org>
  1 sibling, 0 replies; 3+ messages in thread

From: Sergei Kornilov @ 2021-07-12 08:06 UTC (permalink / raw)
  To: ineron@icloud.com <ineron@icloud.com>; pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>

Hello

> Why i get an error if sends text but not error if send digits ?

Because text '123' is valid JSON. text 'text' - not valid. text '"text"' is valid JSON string.

Your example could be reduced to

> select cast(json_build_object('name','name')->>'name' as jsonb);

That means

> select cast('name'::text as jsonb);

Probably you wanted ->'name', not ->>'name'. JSON(b) operator -> will return json/jsonb type.

regards, Sergei





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


end of thread, other threads:[~2021-07-12 08:06 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-07-11 12:40 BUG #17099: Problem with EXECUTE and JSON PG Bug reporting form <noreply@postgresql.org>
2021-07-11 13:48 ` Евгений Илюшин <ineron@icloud.com>
2021-07-12 08:06 ` Sergei Kornilov <sk@zsrv.org>

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