PetaPoco icon indicating copy to clipboard operation
PetaPoco copied to clipboard

PostGreSqlSchemaReader fails if two tables with the same name exists in multiple schemas in the same database

Open missaghi opened this issue 8 years ago • 2 comments

It tried to do a SingleOrDefault on the columns to find the PK but if I have a table in both schemas with the aame column name then the Sequence has multiple elements.

const string COLUMN_SQL=@" SELECT column_name, is_nullable, udt_name, column_default FROM information_schema.columns WHERE table_name=@tableName ";

I've solved this by filtering additionally by table_schema eg: "and table_schema = @tableSchema;"

and adding that the parameter to the LoadColumns method.

I can fork, fix and do a pull request if that's more helpful.

missaghi avatar Dec 15 '16 22:12 missaghi

A PR would be great. There's also integration tests for all the support DBs. Could you please add one to prove it's broken and it's fixed.

pleb avatar Jan 02 '17 06:01 pleb

The integration tests don't seemt o be for the T4 template that I modified. Should I just create a test that mimics the T4 code that threw the error? For now i've submitted a pull request with the fix and some sample SQL for a test: https://github.com/CollaboratingPlatypus/PetaPoco/pull/366

missaghi avatar Feb 02 '17 20:02 missaghi