pg-mem
pg-mem copied to clipboard
Multi-row inserts failing to set default values
Describe the bug
I am having an issue where insert statements with multiple rows, into tables with columns that have default values are failing with the following error: "null value in column "x" violates not-null constraint"
To Reproduce
The SQL to create the table is:
CREATE TABLE "clinic_flow_series_definition_entity" ("createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "id" character varying(255) NOT NULL, "name" character varying(255) NOT NULL, "alternateSeries" boolean NOT NULL DEFAULT false, "type" "public"."clinic_flow_series_definition_entity_type_enum" NOT NULL DEFAULT 'Primary', "seriesDoseCount" integer NOT NULL, "intervals" jsonb NOT NULL, "conceptId" character varying(255), "targetDiseaseId" character varying(255) NOT NULL DEFAULT '840539006', "forecastRuleId" character varying(255) NOT NULL, "deleted" boolean NOT NULL DEFAULT false, "dependentSeriesType" "public"."clinic_flow_series_definition_entity_dependentseriestype_enum", "ageRanges" jsonb NOT NULL DEFAULT '[]', CONSTRAINT "PK_0ccfaa50690078435f73d09420a" PRIMARY KEY ("id"))
When I run an insert statement with a single row like this, it works and the default values are set:
INSERT INTO "clinic_flow_series_definition_entity"("createdAt", "updatedAt", "id", "name", "alternateSeries", "type", "seriesDoseCount", "intervals", "conceptId", "targetDiseaseId", "forecastRuleId", "deleted", "dependentSeriesType", "ageRanges") VALUES (DEFAULT, DEFAULT, '0cc4d9c8-b96e-4424-8d5b-92094f7275dc', 'COVID-19 (mRNA)', 'false', DEFAULT, '2', '[{"max":504,"min":1,"target":28}]', DEFAULT, '840539006', '60308016-38ac-4c60-b72b-8a7fd8efdb4d', 'false', DEFAULT, DEFAULT) RETURNING "createdAt", "updatedAt", "alternateSeries", "type", "targetDiseaseId", "deleted", "ageRanges"
However, if I run an insert with multiple rows, as in the Failed SQL statement below, I get the following error:
QueryFailedError: null value in column "type" violates not-null constraint
🐜 This seems to be an execution error, which means that your request syntax seems okay,
but the resulting statement cannot be executed → Probably not a pg-mem error.
*️⃣ Failed SQL statement: INSERT INTO "clinic_flow_series_definition_entity"("createdAt", "updatedAt", "id", "name", "alternateSeries", "type", "seriesDoseCount", "intervals", "conceptId", "targetDiseaseId", "forecastRuleId", "deleted", "dependentSeriesType", "ageRanges") VALUES (DEFAULT, DEFAULT, '0cc4d9c8-b96e-4424-8d5b-92094f7275dc', 'COVID-19 (mRNA)', 'false', DEFAULT, '2', '[{"max":504,"min":1,"target":28}]', DEFAULT, '840539006', '60308016-38ac-4c60-b72b-8a7fd8efdb4d', 'false', DEFAULT, DEFAULT), (DEFAULT, DEFAULT, '4b12f18e-cff7-4792-9fca-7e6567943318', 'COVID-19 (mRNA), Third Dose Exception', 'false', 'Dependent', '1', '[{"max":10000,"min":28,"target":28}]', DEFAULT, '840539006', '60308016-38ac-4c60-b72b-8a7fd8efdb4d', 'false', 'Exception', DEFAULT) RETURNING "createdAt", "updatedAt", "alternateSeries", "type", "targetDiseaseId", "deleted", "ageRanges";
pg-mem version
2.5.0
I'm generating these queries with Typeorm v0.3.6.
Thanks for creating this library!
I have same problem. any changes? pg-mem: 3.0.2 typeorm: 0.3.7