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.

Create simple test case for failure to load PUDL into Postgresql

See original GitHub issue

As @briannacote noted in #413, there’s some issue which prevents the loading of even an already flattened / simple PUDL data package into a postgres database. @roll thinks this is something which should actually work, but needs a test case to debug it and fix it in the data package libraries.

We need to come up with a simple test case that demonstrates the “non-unique foreign key” issue.

The error which gets thrown:

psycopg2.errors.InvalidForeignKey: there is no unique constraint matching given keys for referenced table "generators_entity_eia"

Resulting from this SQL:

CREATE TABLE ownership_eia860 (
	id SERIAL NOT NULL, 
	report_date DATE, 
	utility_id_eia INTEGER, 
	plant_id_eia INTEGER, 
	generator_id TEXT, 
	operational_status_code TEXT, 
	owner_utility_id_eia INTEGER, 
	owner_name TEXT, 
	owner_state TEXT, 
	owner_city TEXT, 
	owner_street_address TEXT, 
	owner_zip_code TEXT, 
	fraction_owned NUMERIC, 
	PRIMARY KEY (id), 
	FOREIGN KEY(utility_id_eia) REFERENCES utilities_entity_eia (utility_id_eia), 
	FOREIGN KEY(plant_id_eia) REFERENCES generators_entity_eia (plant_id_eia), 
	FOREIGN KEY(generator_id) REFERENCES generators_entity_eia (generator_id)
)

]
(Background on this error at: http://sqlalche.me/e/f405)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rollcommented, Oct 15, 2019

Update

                "foreignKeys": [
                    {
                        "fields": "plant_id_eia",
                        "reference": {
                            "resource": "generators_entity_eia",
                            "fields": "plant_id_eia"
                        }
                    },
                    {
                        "fields": "generator_id",
                        "reference": {
                            "resource": "generators_entity_eia",
                            "fields": "generator_id"
                        }
                    }
                ],

probably should be a composite FK

0reactions
briannacotecommented, Nov 5, 2019

This is awesome! I’ll give it a go soon. I’ve also connected to the SQLite database as well. So we have options now over here. I’ll let you know if I run into any issues again trying it with Postgres.

Also, forgive my delay in getting back. I was out of the office the last two weeks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Loading Test Data into PostgreSQL - Tangram Vision
The simplest way to get test data into PostgreSQL is to make a static dataset, which you can save as CSV files or...
Read more >
Documentation: 15: 33.1. Running the Tests - PostgreSQL
(In case of failure, the stderr messages are usually enough to determine where to look closer.) Alternatively, you can run individual test suites...
Read more >
The Public Utility Data Liberation Project - PUDL documentation
PUDL takes these spreadsheets, CSV files, and databases and turns them into easy to parse, well-documented tabular data packages that can be ...
Read more >
Database (Data) Testing Tutorial with Sample Test Cases
It may involve creating complex queries to load/stress test the ... and information received and stored into database are valid or not.
Read more >
The database abstraction layer - Web2py
If it does not exist, it is created. This file is locked every time it is accessed. In the case of MySQL, PostgreSQL,...
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