question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Insert Statement Fails with no Useful Error

See original GitHub issue

I’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:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
oguimbalcommented, Jan 12, 2021

Like I said in my previous comment, the migrate() function is NOT directly on the IMemoryDb, it is on the ISchema interface.

await db.public.migrate(); // this

await db.getSchema('mySchema').migrate(); // or this, if you have multiple schemas
1reaction
oguimbalcommented, Jan 12, 2021

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:

image

Can you post an example that you can reproduce in the playground if its not the case for you ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

INSERT statement fails without any error message [duplicate]
I am trying to insert values into MySQL database but have not been successful. I have tried to edit the SQL statement several...
Read more >
Why an insert statement fails with SQL1585N error? - IBM
During SQL processing it returned: SQL1585N A temporary table could not be created because there is no available system temporary table ...
Read more >
INSERT Statement error message references column I am not ...
You are just supplying a value for ID, but column Artist has a NOT NULL constraint. When you don't supply a value for...
Read more >
Using the INSERT Statement in SQL - Universal Class
SQL throws you an error when you try to insert duplicate primary key values. When the INSERT statement fails, nothing is inserted into...
Read more >
INSERT INTO - Amazon Athena - AWS Documentation
If a CTAS or INSERT INTO statement fails, it is possible that orphaned data are left in the data location. Because Athena does...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found