-
Notifications
You must be signed in to change notification settings - Fork 13
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 check duplicated foreign key #49
Conversation
Take a look at sqlfluff/sqlfluff#4623 You can try to create a new issue for sqlfluff. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update sql query to correspond other queries in the project
group by 1, 2, 3 | ||
) | ||
select | ||
r_from.relname, -- referencing relation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a domain model in java code for Foreign Keys https://github.com/mfvanek/pg-index-health/blob/master/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/ForeignKey.java
It is necessary to use the same naming as in https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/foreign_keys_without_index.sql#L12
frel_att.atttypmod as rel_att_type_mod, | ||
frel_att.attnotnull as rel_att_notnull | ||
from pg_catalog.pg_constraint as c | ||
cross join lateral unnest(c.conkey) with ordinality as fk_conkey(conkey_number, conkey_order) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to ignore parse error -- noqa: disable=PRS
See also
-- noqa: disable=PRS,ST06,AM06 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the following, but it doesn't seem to resolve the lint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parse error has gone.
There are still some linter errors
== [/github/workspace/sql/check_duplicated_foreign_keys.sql] FAIL
L: 27 | P: 14 | ST09 | Joins should list the table referenced later first.
| [structure.join_condition_order]
L: 27 | P: 39 | AL01 | Implicit/explicit aliasing of table. [aliasing.table]
L: 28 | P: 65 | AL01 | Implicit/explicit aliasing of table. [aliasing.table]
L: 28 | P: 77 | LT01 | WARNING: Expected single whitespace between naked
| identifier and start bracket '('. [layout.spacing]
L: 29 | P: 65 | AL01 | Implicit/explicit aliasing of table. [aliasing.table]
L: 29 | P: 78 | LT01 | WARNING: Expected single whitespace between naked
| identifier and start bracket '('. [layout.spacing]
L: 31 | P: 47 | AL01 | Implicit/explicit aliasing of table. [aliasing.table]
L: 33 | P: 17 | LT03 | Found leading binary operator. Expected only trailing
| near line breaks. [layout.operators]
L: 34 | P: 47 | AL01 | Implicit/explicit aliasing of table. [aliasing.table]
L: 36 | P: 17 | LT03 | Found leading binary operator. Expected only trailing
| near line breaks. [layout.operators]
L: 40 | P: 5 | LT08 | Blank line expected but not found after CTE closing
| bracket. [layout.cte_newline]
L: 50 | P: 1 | LT08 | Blank line expected but not found after CTE closing
| bracket. [layout.cte_newline]
L: 54 | P: 6 | ST09 | Joins should list the table referenced later first.
| [structure.join_condition_order]
L: 54 | P: 33 | AL01 | Implicit/explicit aliasing of table. [aliasing.table]
L: 55 | P: 43 | AL01 | Implicit/explicit aliasing of table. [aliasing.table]
L: 57 | P: 9 | LT03 | Found leading binary operator. Expected only trailing
| near line breaks. [layout.operators]
L: 58 | P: 9 | LT03 | Found leading binary operator. Expected only trailing
| near line breaks. [layout.operators]
L: 59 | P: 9 | LT03 | Found leading binary operator. Expected only trailing
| near line breaks. [layout.operators]
L: 60 | P: 36 | AL01 | Implicit/explicit aliasing of table. [aliasing.table]
All Finished!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the ci of local and remote different? Lint error does not occur in local
It can because in CI newer image used.
left join pg_catalog.pg_attribute as frel_att | ||
on frel_att.attrelid = c.confrelid | ||
and frel_att.attnum = fk_confkey.confkey_number | ||
where c.contype in ('f') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add filtering via schema name. See https://github.com/mfvanek/pg-index-health-sql/blob/master/CONTRIBUTING.md
Superseded by #50 |
Query to check duplicated foreign key
relates mfvanek/pg-index-health#390