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 08:21:44 -0800
Message-ID: <0b0c6908-1b0d-0f3f-4dd3-d6000326b02c@aklaver.com> (raw)
In-Reply-To: <CAADeyWi25Ts_3q8d62CAHvBW8TdsROe-jOVQGSDPB-8qcUXF7g@mail.gmail.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>
<CAADeyWi25Ts_3q8d62CAHvBW8TdsROe-jOVQGSDPB-8qcUXF7g@mail.gmail.com>
On 03/02/2018 06:42 AM, Alexander Farber wrote:
> Hi Adrian, I 100% agree that nobody except me should debug my huge
> stored function, but if you look at my PostgreSQL 10.3 log -
>
Which proves what has already been proven, that at least some of the
data is correct. The issue is data that is not correct as evidenced by
the error message:
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
This is not going to get solved until you identify the 'bad' tiles data.
> 2018-03-02 15:30:33.646 CET [16693] LOG: duration: 0.110 ms parse
> <unnamed>: SELECT out_uid AS uid, out_fcm AS fcm, out_apns AS apns,
> out_adm AS adm, out_body AS body FROM words_play_game($1::int,
> $2::int, $3::jsonb)
> 2018-03-02 15:30:33.646 CET [16693] LOG: duration: 0.058 ms bind
> <unnamed>: SELECT out_uid AS uid, out_fcm AS fcm, out_apns AS apns,
> out_adm AS adm, out_body AS body FROM words_play_game($1::int,
> $2::int, $3::jsonb)
> 2018-03-02 15:30:33.646 CET [16693] DETAIL: parameters: $1 = '7', $2 =
> '609', $3 =
> '[{"col":0,"letter":"К","row":3,"value":2},{"col":0,"letter":"И","row":4,"value":1}]'
> 2018-03-02 15:30:33.646 CET [16693] LOG: execute <unnamed>: SELECT
> out_uid AS uid, out_fcm AS fcm, out_apns AS apns, out_adm AS adm,
> out_body AS body FROM words_play_game($1::int, $2::int, $3::jsonb)
> 2018-03-02 15:30:33.646 CET [16693] DETAIL: parameters: $1 = '7', $2 =
> '609', $3 =
> '[{"col":0,"letter":"К","row":3,"value":2},{"col":0,"letter":"И","row":4,"value":1}]'
>
> I just pass as the 3rd argument in_tiles to my stored function:
> '[{"col":0,"letter":"К","row":3,"value":2},{"col":0,"letter":"И","row":4,"value":1}]'
>
> and then take the in_tiles and store it unchanged in the words_moves table:
>
> INSERT INTO words_moves (
> action,
> gid,
> uid,
> played,
> tiles
> ) VALUES (
> 'play',
> in_gid,
> in_uid,
> CURRENT_TIMESTAMP,
> in_tiles
> ) RETURNING mid INTO STRICT _mid;
>
> Does anybody happen to see what could I do wrong there?
>
> Thank you for any hints
> Alex
>
> P.S: Here my stored fuinction:
> https://gist.github.com/afarber/88a832a1b90a8940764ad69b2b761914
> Here my table:
> https://gist.github.com/afarber/06cc37114ff8dd14f05077f312904361
> And here is how I call the stored function from Java:
>
> String SQL_PLAY_GAME =
> "SELECT " +
> "out_uid AS uid, " +
> "out_fcm AS fcm, " +
> "out_apns AS apns, " +
> "out_adm AS adm, " +
> "out_body AS body " +
> "FROM words_play_game(?::int, ?::int, ?::jsonb)";
>
> private void handlePlay(int gid, String tiles) throws SQLException,
> IOException {
> LOG.info("handlePlay: {} -> {} {}", mUid, gid, tiles);
> try (Connection db = DriverManager.getConnection(DATABASE_URL,
> DATABASE_USER, DATABASE_PASS);
> PreparedStatement st =
> db.prepareStatement(SQL_PLAY_GAME)) {
> st.setInt(1, mUid);
> st.setInt(2, gid);
> st.setString(3, tiles);
> runPlayerAction(st, gid);
> }
> }
--
Adrian Klaver
adrian.klaver@aklaver.com
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: <0b0c6908-1b0d-0f3f-4dd3-d6000326b02c@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> <CAADeyWi25Ts_3q8d62CAHvBW8TdsROe-jOVQGSDPB-8qcUXF7g@mail.gmail.com> <0b0c6908-1b0d-0f3f-4dd3-d6000326b02c@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