Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rye0A-00HIv5-Bc for pgsql-general@arkaria.postgresql.org; Sun, 21 Apr 2024 20:41:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rye08-00G3nF-Ty for pgsql-general@arkaria.postgresql.org; Sun, 21 Apr 2024 20:41:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rye08-00G3n2-J0 for pgsql-general@lists.postgresql.org; Sun, 21 Apr 2024 20:41:28 +0000 Received: from mail-oo1-xc31.google.com ([2607:f8b0:4864:20::c31]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rye06-002E18-1S for pgsql-general@lists.postgresql.org; Sun, 21 Apr 2024 20:41:27 +0000 Received: by mail-oo1-xc31.google.com with SMTP id 006d021491bc7-5aa4204bacdso2322779eaf.2 for ; Sun, 21 Apr 2024 13:41:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713732084; x=1714336884; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=bvFRuhlWln9vHxhaK3o+8czbea9+esnB2CiSkLbHv58=; b=MMlS/s+DvZIFX/1+sgqAB3HX0utoCqD2ClrkibCb+3B3vqpSOxjJKjxcoqM3fDispX u84dVRq3V3GWqBfLI+FiGZFcnwtPWbxN+W8Yfk37RmfI2RS09iKWKXstXBakb6Lk1nRW BAdFNahK1xJE1T/DkYVR0pP30YnmWwkRxl8NLOssRz4aPU9gK+72iLP+n8/XKCAdIjRF rs8rbAIneCnpIM/pY2BxO2NsirQZnkx1HHR21zqdtdDtLZp+ofJieEgccXNfKGOYhYky oh/sya53lnNrd7aJqQ2W6aXwFRtKxpV/+ORK75iToE6q7O+UTTqDgYJLN/sgSKvFpa2o OeWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713732084; x=1714336884; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bvFRuhlWln9vHxhaK3o+8czbea9+esnB2CiSkLbHv58=; b=MkBymoXK7KoqBQv2P8Kn8nMbro8MBHEjcyGm/d1KAwhDwq2QighCTlB99iZmGbdxoy Nzwaahp9pGfsOgAklRNa8SDiCKSVb7itPCd11eW49PxA9rIdxFz/i3+cUj8VaWsUGMWh /U7ZYDs+FNaCPzsVJe0YVhLnjNWZeTOo2aBvgWTg43f9hAvPXP6KCKlgNvv88rqu9h3S 9yzX3Jk78GgafnyM3GVuchtbaFJT4F2WIFpZbDRYHCUcEgUv2UPd30vYAL6o/uunJX+J ymBfGyyiVX06I81jcpFni4JnEnlfKvanwcF6NseKnKIiGZQY8STBP1dhjHCYcdKTvVAf 17RQ== X-Gm-Message-State: AOJu0YywdE57vpxHhNi+3+y9EjRLMzxOLp/0yllLzc7NCSNi8ljPIuLY P1b+aFuSs52yziAzCMnoAM0ki2O8GaUSnQqHBQTZqq2DSDyME0CeOcsmAv5VaL1E2/lDW23Jxiw XjJQ8HEpluZjFuJm3M6cSJ9PThf0= X-Google-Smtp-Source: AGHT+IGh4r8NEnjjnDD+4/5xg6NV8e3mtn4QBLlAhHuulW2u1S1mKu9IfDb9YYWUG7WqCRdB2sRqvuU0cVXsZhmQlw0= X-Received: by 2002:a4a:ad47:0:b0:5ac:bdbe:33f5 with SMTP id s7-20020a4aad47000000b005acbdbe33f5mr9006193oon.3.1713732084141; Sun, 21 Apr 2024 13:41:24 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a8a:d96:0:b0:525:bd21:4d70 with HTTP; Sun, 21 Apr 2024 13:41:23 -0700 (PDT) In-Reply-To: <30b10437-647c-48c9-8bd8-0f45b4af2d7b@erinors.com> References: <30b10437-647c-48c9-8bd8-0f45b4af2d7b@erinors.com> From: "David G. Johnston" Date: Sun, 21 Apr 2024 13:41:23 -0700 Message-ID: Subject: query multiple schemas To: =?UTF-8?Q?Norbert_S=C3=A1ndor?= Cc: "pgsql-general@lists.postgresql.org" Content-Type: multipart/alternative; boundary="0000000000001d95570616a158b3" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000001d95570616a158b3 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sunday, April 21, 2024, Norbert S=C3=A1ndor wrote: > > > The structure of each schema is identical, the tenant ID is the name of > the schema. > You=E2=80=99ve hit the main reason why the scheme you choose is usually avo= ided. Better to just add tenant_id to your tables in the first place. And use partitioned tables if you desire physical separation. > The above solution seems to work, my questions are: > > 1. Is there a better way to achieve the same functionality? Maybe > without using JSON as an intermediate representation? > > In-database, I doubt it (though I didn=E2=80=99t study your specific soluti= on in depth). Json provides the easiest way to generate the virtual tables you need. Otherwise maybe try something with say bash scripting and psql scripts; or some other client-side setup where you separate the query and the metadata lookups so the queries just return normal results and the client takes them are merges them. David J. --0000000000001d95570616a158b3 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sunday, April 21, 2024, Norbert S=C3=A1ndor <sandor.norbert@erinors.com> = wrote:


The structure of each schema is identical, the tenant ID is the name of the schema.

You=E2=80=99ve hit the= main reason why the scheme you choose is usually avoided.=C2=A0 Better to = just add tenant_id to your tables in the first place.=C2=A0 And use partiti= oned tables if you desire physical separation.

The above solution seems to work, my questions are:

  1. Is there a better way to achieve the same functionality? Maybe without using JSON as an intermediate representation?

In-database, I doubt it (though I didn= =E2=80=99t study your specific solution in depth).=C2=A0 Json provides the = easiest way to generate the virtual tables you need.

Otherwise maybe try something with say bash scripting and psql scripts; = or some other client-side setup where you separate the query and the metada= ta lookups so the queries just return normal results and the client takes t= hem are merges them.

David J.
--0000000000001d95570616a158b3--