Insert Statement Fails with no Useful Error
See original GitHub issueI’m having a hard time troubleshooting this.
While I can log any failed sql statements that pg-mem via inMemoryDb.on('query-failed', it doesn’t tell me what the problem is exactly.
This query was successfully migrated to my production database using flyway. This same kind of statement also ran ok in my 001 migration but just not my 003 for this community table insert which is really odd.
Here’s a screencast on this: https://youtu.be/yaWBzsUtJbE
(note: I’ve replaced the real strings with x’s for privacy for this post)
INSERT INTO public.community (name,image_url,twitter_url,coordinates,meetup_url,main_site_url,slack_url,facebook_url,github_url,eventbrite_url,linkedin_url) VALUES ('xxxxxxxxxx','xxxxxxxxxxx',NULL,'(33.7676338,-84.6176515)','xxxxxxxxxx',NULL,NULL,NULL,NULL,NULL,NULL);
Also tried
INSERT INTO community VALUES ('Software Crafters - Atlanta','https://storage.googleapis.com/wedotdd-client-assets/assets/communities/assets_communities_software-crafters-atlanta.png',NULL,point(33.7676338,-84.6176515),'https://www.meetup.com/Software-Craftsmanship-Atlanta',NULL,NULL,NULL,NULL,NULL,NULL);
Now the initial migration that creates the schema looks like this for my pg-mem 001 migration for the community table:
CREATE TABLE community (
community_id integer NOT NULL,
name character varying NOT NULL,
image_url character varying,
twitter_url character varying,
coordinates point,
meetup_url character varying,
main_site_url character varying,
slack_url character varying,
facebook_url character varying,
github_url character varying,
eventbrite_url character varying,
linkedin_url character varying
);
ALTER TABLE community ALTER COLUMN community_id ADD GENERATED ALWAYS AS IDENTITY (
SEQUENCE NAME community_community_id_seq
START WITH 0
INCREMENT BY 1
MINVALUE 0
NO MAXVALUE
CACHE 1
);
The only thing to note in addition is that in my 001 migration related to community at the end of that script is:
ALTER TABLE ONLY community_location ADD CONSTRAINT community_country_pkey PRIMARY KEY (community_id, location_id);
ALTER TABLE ONLY community ADD CONSTRAINT community_pkey PRIMARY KEY (community_id);
ALTER TABLE ONLY location ADD CONSTRAINT location_pkey PRIMARY KEY (location_id);
ALTER TABLE ONLY skill_type ADD CONSTRAINT skill_type_pkey PRIMARY KEY (skill_type_id);
ALTER TABLE ONLY skills ADD CONSTRAINT skills_pkey PRIMARY KEY (skill_id);
ALTER TABLE ONLY location ADD CONSTRAINT city_id_fk FOREIGN KEY (city_id) REFERENCES city(city_id) MATCH FULL;
ALTER TABLE ONLY community_location ADD CONSTRAINT community_id_fk FOREIGN KEY (community_id) REFERENCES community(community_id) MATCH FULL;
ALTER TABLE ONLY location ADD CONSTRAINT country_id_fk FOREIGN KEY (country_id) REFERENCES country(country_id) MATCH FULL;
ALTER TABLE ONLY community_location ADD CONSTRAINT location_id_fk FOREIGN KEY (location_id) REFERENCES location(location_id) MATCH FULL;
ALTER TABLE ONLY location ADD CONSTRAINT state_id_fk FOREIGN KEY (state_id) REFERENCES state(state_id) MATCH FULL;
If I disable those ALTER statements at then end then change the script to include the community_id, then this works (noice the ID 31):
INSERT INTO community VALUES (31, 'xxxxx', 'xxxxx', NULL, '(-77.03059944399082,-12.045945732454783)', 'xxxxx', NULL, NULL, NULL, NULL, NULL, NULL);
But…I should not have to disable those alter statements AND I shouldn’t have to specify a community_id in my insert because I’ve turned on ADD GENERATED ALWAYS AS IDENTITY which will create the ID for me automatically.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (5 by maintainers)

Top Related StackOverflow Question
Like I said in my previous comment, the migrate() function is NOT directly on the
IMemoryDb, it is on theISchemainterface.There still is a dettached promise line 2 here.
This cannot work well. It might work by accident, but there are concurrency issues with this, meaning that it might have an erratic behaviour, and might behave otherwise on another machine than yours.
The point literal syntax works well, as far as I can tell:
Can you post an example that you can reproduce in the playground if its not the case for you ?