Re: TSQL To Postgres - Unpivot/Union All

2023-07-20 Thread Anthony Apollis
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

Re: Fwd: TSQL To Postgres - Unpivot/Union All

2023-07-20 Thread Thomas Kellerer
Anthony Apollis schrieb am 20.07.2023 um 14:17: Does not give me outputs for columns: Metric and Pricing Channel: image.png What am i doing wrong? Please assist? UNPIVOT can be done using a LATERAL sub-query with a VALUES clause: https://blog.sql-workbench.eu/post/unpivot-with-postgres/

Re: TSQL To Postgres - Unpivot/Union All

2023-07-20 Thread Geoff Winkless
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

Fwd: TSQL To Postgres - Unpivot/Union All

2023-07-20 Thread Anthony Apollis
-- Forwarded message - From: Anthony Apollis Date: Thu, 20 Jul 2023 at 16:07 Subject: Re: TSQL To Postgres - Unpivot/Union All To: Geoff Winkless , David G. Johnston < david.g.johns...@gmail.com> I am attaching my TSQL and Postgres SQL: On Thu, 20 Jul 2023 at 15:58,

Re: TSQL To Postgres - Unpivot/Union All

2023-07-20 Thread Geoff Winkless
On Thu, 20 Jul 2023 at 13:17, Anthony Apollis wrote: > The Postgres i used: INSERT INTO temp_FieldFlowsFact > SELECT "Account", "Calendar day", "Financial year", "Period", > > [snip] At the very least, include a column list in your INSERT statement. We have no way of checking where any of your

Re: TSQL To Postgres - Unpivot/Union All

2023-07-20 Thread David G. Johnston
On Thursday, July 20, 2023, Anthony Apollis wrote: > > > I am trying to convert this TSQL: > This doesn’t really seem relevant all that relevant at this point. Given some input data either the query produces the expected result or it doesn’t. > > What am i doing wrong? Please assist? > You