pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Alexander Farber <alexander.farber@gmail.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: jsonb_array_length: ERROR: 22023: cannot get array length of a scalar
Date: Fri, 2 Mar 2018 06:31:34 -0800
Message-ID: <39bf9413-1465-9880-24e0-ee8d1c84e8a0@aklaver.com> (raw)
In-Reply-To: <CAADeyWhx0B_z4at-X6sMqz+m6sr28U4kaxmKFcqphYYV7UuAuw@mail.gmail.com>
References: <CAADeyWhfBuFiWz0Au0J2XyU5ZTDCBionqMGHqL657xseWq913g@mail.gmail.com>
	<0325b36d-f990-deb9-3086-0fb626c95e14@aklaver.com>
	<CAADeyWhx0B_z4at-X6sMqz+m6sr28U4kaxmKFcqphYYV7UuAuw@mail.gmail.com>

On 03/02/2018 06:14 AM, Alexander Farber wrote:
> Hi Adrian, thank you for the reply -
> 

>         #  select mid, jsonb_array_length(tiles) from words_moves where
>         gid=609;
>         ERROR:  22023: cannot get array length of a scalar
>         LOCATION:  jsonb_array_length, jsonfuncs.c:1579
> 
>         What am I doing wrong here please?
> 
> 
>     Are you sure all the values in tiles are correctly formatted because
>     when I use jsonb_array_length with the provided data:
> 
>     test=# select jsonb_array_length( '[{"col": 3, "row": 7, "value": 2,
>     "letter": "С"}, {"col": 4, "row": 7, "value": 1, "letter": "О"},
>     {"col": 5, "row": 7, "value": 2, "letter": "П"}, {"col": 6, "row":
>     7, "value": 0, "letter": "Л"}, {"col": 7, "row": 7, "value": 3,
>     "letter": "Я"}]');
>       jsonb_array_length
>     --------------------
>                        5
> 
> 
> I fill that table with the following stored function (please pardon the 
> huge listing):

The little gray cells are not awake enough to work through the below:) 
If it where me I would first confirm there was malformed data by looking 
at the data itself. If there are not that many records for gid = 609 
maybe a simple select  of tiles would be sufficient. Otherwise maybe a 
simple plpgsql function that loops through the records applying 
jsonb_array_length and raising a notice on the error. In any case the 
point is to identify the presence of malformed data and if present the 
nature of the malformation. That would help reverse engineer any issues 
with below.

> 
> CREATE OR REPLACE FUNCTION words_play_game(
>                  in_uid   integer,
>                  in_gid   integer,
>                  in_tiles jsonb
>          ) RETURNS table (
>                  out_uid  integer, -- the player to be notified
>                  out_fcm  text,
>                  out_apns text,
>                  out_adm  text,
>                  out_body text
>          ) AS



-- 
Adrian Klaver
adrian.klaver@aklaver.com




view thread (18+ messages)  latest in thread

Message-ID: <39bf9413-1465-9880-24e0-ee8d1c84e8a0@aklaver.com>
Permalink:  ../39bf9413-1465-9880-24e0-ee8d1c84e8a0@aklaver.com/
Also on:    postgresql.org/message-id/39bf9413-1465-9880-24e0-ee8d1c84e8a0@aklaver.com

 · 

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: adrian.klaver@aklaver.com, alexander.farber@gmail.com
  Subject: Re: jsonb_array_length: ERROR: 22023: cannot get array length of a scalar
  In-Reply-To: <39bf9413-1465-9880-24e0-ee8d1c84e8a0@aklaver.com>
  References: <CAADeyWhfBuFiWz0Au0J2XyU5ZTDCBionqMGHqL657xseWq913g@mail.gmail.com> <0325b36d-f990-deb9-3086-0fb626c95e14@aklaver.com> <CAADeyWhx0B_z4at-X6sMqz+m6sr28U4kaxmKFcqphYYV7UuAuw@mail.gmail.com> <39bf9413-1465-9880-24e0-ee8d1c84e8a0@aklaver.com>

* 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