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 check duplicated foreign key #49

Closed
wants to merge 3 commits into from
Closed

Conversation

BLoHny
Copy link
Collaborator

@BLoHny BLoHny commented Sep 5, 2024

Query to check duplicated foreign key

relates mfvanek/pg-index-health#390

@BLoHny BLoHny requested a review from mfvanek September 5, 2024 02:19
@BLoHny
Copy link
Collaborator Author

BLoHny commented Sep 5, 2024

image

Other lint errors have been fixed, But
In the current sqlfluff version, I think it can't parse "cross join lateral".
Is there a solution?

@mfvanek
Copy link
Owner

mfvanek commented Sep 6, 2024

image

Other lint errors have been fixed, But In the current sqlfluff version, I think it can't parse "cross join lateral". Is there a solution?

Take a look at sqlfluff/sqlfluff#4623

You can try to create a new issue for sqlfluff.

Copy link
Owner

@mfvanek mfvanek left a 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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Owner

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

Copy link
Collaborator Author

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.

Copy link
Owner

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!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Are the ci of local and remote different? Lint error does not occur in local

Copy link
Owner

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')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mfvanek
Copy link
Owner

mfvanek commented Oct 5, 2024

Superseded by #50

@mfvanek mfvanek closed this Oct 5, 2024
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

Successfully merging this pull request may close these issues.

2 participants