You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.8 KiB

CREATE TABLE public.aw_eka
(
"KODS" integer NOT NULL,
"TIPS_CD" smallint,
"STATUSS" character(3),
"APSTIPR" character(1),
"APST_PAK" character(3),
"VKUR_CD" integer,
"VKUR_TIPS" smallint,
"NOSAUKUMS" text,
"SORT_NOS" text,
"ATRIB" character(7),
"PNOD_CD" varchar(10),
"DAT_SAK" date,
"DAT_MOD" character varying(23),
"DAT_BEIG" character varying(18),
"FOR_BUILD" character(1),
"PLAN_ADR" character(1),
"STD" text,
"KOORD_X" character varying(12),
"KOORD_Y" character varying(12),
"DD_N" character varying(13),
"DD_E" character varying,
PRIMARY KEY ("KODS")
);
ALTER TABLE IF EXISTS public.aw_eka
OWNER to augusts;
COPY aw_eka FROM '/home/augusts/darbs/AW_EKA.CSV' DELIMITER ';' CSV HEADER QUOTE '#';
ALTER TABLE IF EXISTS public.aw_eka
RENAME "APST_PAK" TO "APST_PAK_txt";
ALTER TABLE IF EXISTS public.aw_eka
RENAME "PNOD_CD" TO "PNOD_CD_txt";
ALTER TABLE IF EXISTS public.aw_eka
RENAME "DAT_MOD" TO "DAT_MOD_txt";
ALTER TABLE IF EXISTS public.aw_eka
RENAME "DAT_BEIG" TO "DAT_BEIG_txt";
ALTER TABLE IF EXISTS public.aw_eka
RENAME "KOORD_X" TO "KOORD_X_txt";
ALTER TABLE IF EXISTS public.aw_eka
RENAME "KOORD_Y" TO "KOORD_Y_txt";
ALTER TABLE IF EXISTS public.aw_eka
RENAME "DD_N" TO "DD_N_txt";
ALTER TABLE IF EXISTS public.aw_eka
RENAME "DD_E" TO "DD_E_txt";
ALTER TABLE IF EXISTS public.aw_eka
ADD COLUMN "APST_PAK" smallint;
ALTER TABLE IF EXISTS public.aw_eka
ADD COLUMN "PNOD_CD" integer;
ALTER TABLE IF EXISTS public.aw_eka
ADD COLUMN "DAT_MOD" date;
ALTER TABLE IF EXISTS public.aw_eka
ADD COLUMN "DAT_BEIG" date;
ALTER TABLE IF EXISTS public.aw_eka
ADD COLUMN "KOORD_X" numeric(9, 3);
ALTER TABLE IF EXISTS public.aw_eka
ADD COLUMN "KOORD_Y" numeric(9, 3);
ALTER TABLE IF EXISTS public.aw_eka
ADD COLUMN "DD_E" numeric(8, 6);
ALTER TABLE IF EXISTS public.aw_eka
ADD COLUMN "DD_W" numeric(8, 6);
UPDATE aw_eka SET "DAT_BEIG_txt" = NULL WHERE "DAT_BEIG_txt" = '';
UPDATE aw_eka SET "DAT_BEIG_txt" = NULL WHERE "APST_PAK_txt" = '';
UPDATE aw_eka SET "PNOD_CD_txt" = NULL WHERE "PNOD_CD_txt" = '';
UPDATE aw_eka SET "KOORD_X_txt" = NULL WHERE "KOORD_X_txt" = '';
UPDATE aw_eka SET "KOORD_Y_txt" = NULL WHERE "KOORD_Y_txt" = '';
UPDATE aw_eka SET "DD_E_txt" = NULL WHERE "DD_E_txt" = '';
UPDATE aw_eka SET "DD_N_txt" = NULL WHERE "DD_N_txt" = '';
UPDATE aw_eka SET "KOORD_X" = TO_NUMBER("KOORD_X_txt", '999999D999');
UPDATE aw_eka SET "KOORD_Y" = TO_NUMBER("KOORD_Y_txt", '999999D999');
UPDATE aw_eka SET "DD_E" = TO_NUMBER("DD_E_txt", '999999D999');
UPDATE aw_eka SET "DD_N" = TO_NUMBER("DD_N_txt", '999999D999');
UPDATE aw_eka SET "APST_PAK_txt" = NULL WHERE "APST_PAK_txt" = '';
UPDATE aw_eka SET "APST_PAK" = TO_NUMBER("APST_PAK_txt", '999') WHERE "APST_PAK_txt" IS NOT NULL;
ALTER TABLE IF EXISTS public.aw_eka
RENAME "FOR_BUILD" TO "DAT_MOD_txt";
ALTER TABLE IF EXISTS public.aw_eka
RENAME "FOR_BUILD" TO "DAT_MOD_txt";
ALTER TABLE IF EXISTS public.aw_eka
RENAME "PLAN_ADR" TO "PLAN_ADR_txt";
ALTER TABLE IF EXISTS public.aw_eka
ADD COLUMN "FOR_BUILD" boolean;
ALTER TABLE IF EXISTS public.aw_eka
ADD COLUMN "PLAN_ADR" boolean;
ALTER TABLE IF EXISTS public.aw_eka
ADD COLUMN "APSTIPR" boolean;
UPDATE aw_eka SET "APSTIPR" = 'n' WHERE "APSTIPR_txt" = '';
UPDATE aw_eka SET "FOR_BUILD" = 'n' WHERE "FOR_BUILD_txt" = 'N';
UPDATE aw_eka SET "PLAN_ADR" = 'n' WHERE "FOR_BUILD_txt" = 'N';
UPDATE aw_eka SET "PLAN_ADR" = 'y' WHERE "PLAN_ADR_txt" = 'Y';
UPDATE aw_eka SET "APSTIPR" = 'y' WHERE "APSTIPR_txt" = 'Y';
UPDATE aw_eka SET "FOR_BUILD" = 'y' WHERE "FOR_BUILD_txt" = 'Y';
SELECT "APSTIPR","FOR_BUILD", "PLAN_ADR" FROM aw_eka;