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 1qMVtA-002Zyj-Vp for pgsql-general@arkaria.postgresql.org; Thu, 20 Jul 2023 15:48:24 +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 1qMVsB-00B3SA-9M for pgsql-general@arkaria.postgresql.org; Thu, 20 Jul 2023 15:47:23 +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 1qMVsA-00B3S1-Ui for pgsql-general@lists.postgresql.org; Thu, 20 Jul 2023 15:47:22 +0000 Received: from mail-lj1-x233.google.com ([2a00:1450:4864:20::233]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qMVs7-000fuf-Pz for pgsql-general@lists.postgresql.org; Thu, 20 Jul 2023 15:47:22 +0000 Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2b701e1ca63so14758041fa.1 for ; Thu, 20 Jul 2023 08:47:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689868040; x=1690472840; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=hd1Sl1ZDakA7XIpX8lyTtMp1FHbGalNJ9dQqksfN9SY=; b=qB9YJk8S///6jkVUEoxwR4nIe8rT+cSamjhlbM4IruOmtlfsBsA5gOsWGv1uacfiat osYgljR6WeYMnVwC6Pg+VH3BSR58va1LGmeGU2UTOdmtuEUnTG4bOP5ptT8cPMrVAZyg ZHOKaPhiMmr7RaLLWA7BmGzKaGKgZ8odsm5DvsSxOFL8UVJ0HjUqxcjeJGJJ1aFNXHLM x3K6PLHc/HP1u3pLnejwAeMaS/XPDuj1YLvj1zGr+p6UwVnxfjh4Msfdu9+X0vRfezDQ DiA7uQpv4IOGfyQpujKbWMi1gqRlMN8qfpP6gq8iGGxpVyUR0Pa2NKEvnZjAAwvuUWx/ zxiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689868040; x=1690472840; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=hd1Sl1ZDakA7XIpX8lyTtMp1FHbGalNJ9dQqksfN9SY=; b=Jh44G0niUL6SalepPHIMEvDfLpsBt9xLdFTg++1iTHcOTdx+GMmpKx/KSPZ3NUbCB6 QRW+85unMjmqkiSop7Bt/RZ6UPHtxT3EdjYIf5irX7FIUsOSoXzh6NCBqDxhsgI01I1R ToEacLe6Qk29Htyj3qFjYCB4Cke9LP57rTsbyZMzXf1Mjqf/cZEx+dJDCLJcHdYtbv4Z ogFKbJfCsCJV9ZRjqQAfUglltqellLFeWkSPfkUgqNuXxy+NPxiVFoY99KjhYNG3it5c asaOXrridPrQpjCDKkVGGwIGgEOUZOl5i4VKuPHxfEo1Z47sJgrkHZvMn3NeZ1qdCvjt 4QQg== X-Gm-Message-State: ABy/qLZRdQHIds91Mb5mtFYLobWQ5bLbvCLc51Ix9g/srFkYzobEtieX nYTUy3aeY/UEionVwCUHKpdgciKaMm0Oz/f8FJkRKYtS3s6KYQ== X-Google-Smtp-Source: APBJJlFWWvvEcTj8M1n61vXuenirmpcxp6Nr2OlP4uqMjdDOtyk8dVTM98l+Qp35hI9fXj4xR9IUYambq3LunCGEOm0= X-Received: by 2002:a2e:8841:0:b0:2b6:dc84:b93e with SMTP id z1-20020a2e8841000000b002b6dc84b93emr2593780ljj.21.1689868039718; Thu, 20 Jul 2023 08:47:19 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Anthony Apollis Date: Thu, 20 Jul 2023 17:47:08 +0200 Message-ID: Subject: Re: TSQL To Postgres - Unpivot/Union All To: Geoff Winkless Cc: pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000003989eb0600ed1049" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000003989eb0600ed1049 Content-Type: text/plain; charset="UTF-8" CREATE TEMP TABLE temp_FieldFlowsFact ( Account varchar(20), "Calendar day" DATE, "Financial year" varchar(5), Period varchar(8), "Period type" varchar(10), Metric varchar(50), "Metric Value" float ) It was created as a temp table in SQLServer, but it does not have to be in Postgres. Thanks On Thu, 20 Jul 2023 at 16:51, Geoff Winkless wrote: > On Thu, 20 Jul 2023 at 15:28, Anthony Apollis > wrote: > > I am attaching my TSQL and Postgres SQL: > > You're still missing some CREATEs, for example for temp_FieldFlowsFact. > > Even assuming your columns list is correct, I would still (and as a > matter of habit) include the target column list in your INSERT > statements, if only to make your own life easier, but especially > because any later changes to the tables could end up shifting the > position of the columns. > > Certainly it will be easier for anyone else trying to disentangle the SQL > later. > > As an aside, can you clarify whether you mean temporal tables (and are > you using a temporal tables extension)? Or should that read > "temporary"? > > Geoff > --0000000000003989eb0600ed1049 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
CREATE TEMP TABLE temp_FieldFlowsFact (
=C2=A0 =C2=A0 A= ccount varchar(20),
=C2=A0 =C2=A0 "Calendar day" DATE,
=C2= =A0 =C2=A0 "Financial year" varchar(5),
=C2=A0 =C2=A0 Period v= archar(8),
=C2=A0 =C2=A0 "Period type" varchar(10),
=C2=A0 = =C2=A0 Metric varchar(50),
=C2=A0 =C2=A0 "Metric Value" float<= br>)
It was created as a temp table in SQLServer, but it does not h= ave to be in Postgres. Thanks

On Thu, 20 Jul 2023 at 16:51, Geoff Wink= less <pgsqladmin@geoff.dj>= wrote:
On Thu, = 20 Jul 2023 at 15:28, Anthony Apollis <anthony.apollis@gmail.com> wrote:
> I am attaching my TSQL and Postgres SQL:

You're still missing some CREATEs, for example for temp_FieldFlowsFact.=

Even assuming your columns list is correct, I would still (and as a
matter of habit) include the target column list in your INSERT
statements, if only to make your own life easier, but especially
because any later changes to the tables could end up shifting the
position of the columns.

Certainly it will be easier for anyone else trying to disentangle the SQL l= ater.

As an aside, can you clarify whether you mean temporal tables (and are
you using a temporal tables extension)? Or should that read
"temporary"?

Geoff
--0000000000003989eb0600ed1049--