Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mfo7r-0008Qq-Ai for pgsql-general@arkaria.postgresql.org; Wed, 27 Oct 2021 18:58:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mfo7o-0001L9-AN for pgsql-general@arkaria.postgresql.org; Wed, 27 Oct 2021 18:58:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mfo7n-0001Kz-V3 for pgsql-general@lists.postgresql.org; Wed, 27 Oct 2021 18:58:12 +0000 Received: from mail.tuxteam.de ([5.199.139.25]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.92) (envelope-from ) id 1mfo7l-0005qW-CV for pgsql-general@lists.postgresql.org; Wed, 27 Oct 2021 18:58:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tuxteam.de; s=mail; h=From:Content-Type:MIME-Version:Message-ID:Subject:To:Date; bh=pLN+IuIVfYNqtRnBXbZs7Gc+fKa2gEVACg13WZs7SOU=; b=a2dRVeeOyvDh87lsvCEWQTBOo4T1/py3tQG6X1b/0pple4ddvChmhxn+8j9eftSxuftgqrnfq+ssGoZaUVYWtsmv1zXgkXL43ljhae1UefqjEwqD3Fll3v5qtpgrJ2gqKyDtPiEMHpcmVdCrDmhLrphr1fVjWxACeOK8JpPH2nUFO933SWEag5oTTbJ3+wIsHYMO6FlFatCn2nW7gLgsaGGZ4lFHD8ekxD7PknIRJ4DQ21JUNHwF7cCjfVOSW2lDYCjRHwtfUzz9CSj/dh3y+g22Ky+8en+340Jfn5r6mMxPCysZy/ljEQc2ZS3KY2XVoHcDnJzMruVQi70GNCvuxg==; Received: from tomas by mail.tuxteam.de with local (Exim 4.80) (envelope-from ) id 1mfo7j-0008IQ-JA for pgsql-general@lists.postgresql.org; Wed, 27 Oct 2021 20:58:07 +0200 Date: Wed, 27 Oct 2021 20:58:07 +0200 To: pgsql-general@lists.postgresql.org Subject: jsonb: unwrapping text Message-ID: <20211027185807.GA31130@tuxteam.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="y0ulUmNC+osPPQO6" Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) From: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --y0ulUmNC+osPPQO6 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, I'm trying to extract text from a jsonb 'string'. Simply casting gives me the string wrapped in quotes: foo=3D# select '"foo"'::jsonb::text; text =20 ------- "foo" (1 row) This, of course, makes kind of sense, since it /is/ the JSON's textual representation. What is the canonical way to get at the string's content itself? I've found out that one can treat a string singleton as if it were an array: foo=3D# select '"foo"'::jsonb ->> 0; ?column?=20 ---------- foo (1 row) which conveniently returns the right type. My question: can I rely on that, or am I missing a much more obvious option? (I try to stay compatible down to PostgreSQL 11, 9 when possible. Conservative customers and that). Thanks for any insights, cheers -- tom=C3=A1s --y0ulUmNC+osPPQO6 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAmF5oT8ACgkQBcgs9XrR2kaCNgCfVALXq97dsdvlSreibV8B9/Nu MzcAniO/3Pm91xbBgmQ1OQXKNGl5acf5 =op51 -----END PGP SIGNATURE----- --y0ulUmNC+osPPQO6--