Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query to information_schema.columns selects columns from all schemas #32

Open
rwest202 opened this issue Mar 14, 2019 · 3 comments
Open

Comments

@rwest202
Copy link

rwest202 commented Mar 14, 2019

const getColumns = 'select * from information_schema.columns ' +
`where table_name = '${mappedType}'`

Let's say I have a schema named schema-v1 and another named schema-v2 that both have a table called users. If schema-v1 has a column in users like users.email then the below if statement will wrongly think that the column exists in schema-v2. This is because information_schema.columns returns a list of columns in all schemas.

if (!tableColumns[type].some(row => row.column_name === field) &&

Solution should be to specify the exact schema to search in.

@gr0uch
Copy link
Member

gr0uch commented Mar 14, 2019

Hmm I see, but does this cause any errors?

@rwest202
Copy link
Author

It doesn't add the columns to the new schema, since it thinks they already exist. I was able to resolve my issue by removing the schema-v1. But it wasn't immediately obvious what was causing the issue.

@rwest202
Copy link
Author

rwest202 commented Mar 14, 2019

Looks like there is a table_schema key that you can check against, so something like

if (!tableColumns[type].some(row => row.column_name === field && row.table_schema === currentSchema)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants