pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #18222: Unexpected Error--Cannot delete from scalar
4+ messages / 4 participants
[nested] [flat]

* BUG #18222: Unexpected Error--Cannot delete from scalar
@ 2023-12-04 05:56  PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 2 replies; 4+ messages in thread

From: PG Bug reporting form @ 2023-12-04 05:56 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: bajinsheng@u.nus.edu

The following bug has been logged on the website:

Bug reference:      18222
Logged by:          Jinsheng Ba
Email address:      bajinsheng@u.nus.edu
PostgreSQL version: 16.1
Operating system:   Ubuntu
Description:        

SELECT ('1'-to_hex(2))::BOOLEAN; -- ERROR:  cannot delete from scalar

This error looks strange to me as I do not understand what this error
means.

If I execute the following query, there is no error instead:
SELECT '1'-2; -- {-2}



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

* Re: BUG #18222: Unexpected Error--Cannot delete from scalar
@ 2023-12-04 13:50  Laurenz Albe <laurenz.albe@cybertec.at>
  parent: PG Bug reporting form <noreply@postgresql.org>
  1 sibling, 0 replies; 4+ messages in thread

From: Laurenz Albe @ 2023-12-04 13:50 UTC (permalink / raw)
  To: bajinsheng@u.nus.edu; pgsql-bugs@lists.postgresql.org

On Mon, 2023-12-04 at 05:56 +0000, PG Bug reporting form wrote:
> PostgreSQL version: 16.1
> 
> SELECT ('1'-to_hex(2))::BOOLEAN; -- ERROR:  cannot delete from scalar
> 
> This error looks strange to me as I do not understand what this error
> means.
> 
> If I execute the following query, there is no error instead:
> SELECT '1'-2; -- {-2}

That's not a bug.

PostgreSQL infers the operator jsonb - text.  '1' gives a valid "jsonb"
scalar, but you cannot remove an attribute from a JSON scalar.

I cannot tell you what to do, because your expression makes as little
sense to me as it does to PostgreSQL.

Yours,
Laurenz Albe





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

* Re: BUG #18222: Unexpected Error--Cannot delete from scalar
@ 2023-12-04 14:15  Tom Lane <tgl@sss.pgh.pa.us>
  parent: PG Bug reporting form <noreply@postgresql.org>
  1 sibling, 1 reply; 4+ messages in thread

From: Tom Lane @ 2023-12-04 14:15 UTC (permalink / raw)
  To: bajinsheng@u.nus.edu; +Cc: pgsql-bugs@lists.postgresql.org

PG Bug reporting form <noreply@postgresql.org> writes:
> SELECT ('1'-to_hex(2))::BOOLEAN; -- ERROR:  cannot delete from scalar

> This error looks strange to me as I do not understand what this error
> means.

Just out of curiosity, what did you expect that to do?

to_hex() produces type text, and there's no "text - text" operator.
What's evidently happening is that the parser finds "jsonb - text"
(i.e., jsonb_delete) as the only potentially applicable operator.
It successfully coerces '1' to a scalar jsonb value, but then
jsonb_delete() spits up because it's expecting an array.

I'm not sure that it was such a great idea to define '-' as having
this meaning for jsonb, but it's been there awhile now so probably
too late to change.

			regards, tom lane





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

* Re: BUG #18222: Unexpected Error--Cannot delete from scalar
@ 2023-12-04 14:21  Ba Jinsheng <bajinsheng@u.nus.edu>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Ba Jinsheng @ 2023-12-04 14:21 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>

I thought it would probably give a warning that no available operator for text-text, not this error.
Anyway, thanks!
________________________________
From: Tom Lane <tgl@sss.pgh.pa.us>
Sent: Monday, December 4, 2023 10:15:46 PM
To: Ba Jinsheng <bajinsheng@u.nus.edu>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: BUG #18222: Unexpected Error--Cannot delete from scalar

        - External Email -



PG Bug reporting form <noreply@postgresql.org> writes:
> SELECT ('1'-to_hex(2))::BOOLEAN; -- ERROR:  cannot delete from scalar

> This error looks strange to me as I do not understand what this error
> means.

Just out of curiosity, what did you expect that to do?

to_hex() produces type text, and there's no "text - text" operator.
What's evidently happening is that the parser finds "jsonb - text"
(i.e., jsonb_delete) as the only potentially applicable operator.
It successfully coerces '1' to a scalar jsonb value, but then
jsonb_delete() spits up because it's expecting an array.

I'm not sure that it was such a great idea to define '-' as having
this meaning for jsonb, but it's been there awhile now so probably
too late to change.

                        regards, tom lane

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


end of thread, other threads:[~2023-12-04 14:21 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-12-04 05:56 BUG #18222: Unexpected Error--Cannot delete from scalar PG Bug reporting form <noreply@postgresql.org>
2023-12-04 13:50 ` Laurenz Albe <laurenz.albe@cybertec.at>
2023-12-04 14:15 ` Tom Lane <tgl@sss.pgh.pa.us>
2023-12-04 14:21   ` Ba Jinsheng <bajinsheng@u.nus.edu>

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