Created
September 1, 2022 11:00
-
-
Save ruchej/79a701b7b74da55636f40ce64ef4944e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE PROCEDURE CREATE_TABLE_TRANSFORMED_DATA() | |
LANGUAGE 'plpgsql' | |
AS $$ | |
CREATE TABLE IF NOT EXISTS public.transformed_data | |
( | |
value_timestamp timestamp without time zone NOT NULL, | |
CONSTRAINT transformed_data_pkey PRIMARY KEY (value_timestamp) | |
); | |
DECLARE names ARRAY; | |
NAMES := (SELECT DISTINCT VALUE_NAME FROM DATA_FROM_KAFKA); | |
BEGIN | |
FOREACH NAME in ARRAY NAMES | |
LOOP | |
EXECUTE 'ALTER TABLE public.transformed_data ADD COLUMN %I double precision;' | |
USING format(%I, NAME); | |
END LOOP; | |
END; | |
$$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment