Within Postgres, it's possible (and sometimes necessary) to put double quotes around table & column names. This causes undesired behavior within sql_metadata:
get_query_columns won't find any columns, even if they exist.
get_query_tables identifies the table names (though it doesn't recognize the quotes as being part of the name and will only return the unquoted part).
generalize_sql will generify both table and column names, which defeats the point of the call.
I'm able to work around the table issue by using the result of get_query_table to remove the quotes around the table names from the query, so that generalize_sql won't eat my table names - but this trick doesn't work for the columns, as get_query_columns doesn't recognize them.
Reasons why this should be implemented:
- Legacy projects that can't just rewrite their database scheme
- Django projects. <-- I'm part of this group. Even though Django generates valid Postgres table & column names (e. g. lowercase names without spaces), it will still quote them when constructing the queries because it's possible to manually specify names - and by using quotes, the chosen names won't cause errors. And the quotes are valid syntax for Postgres (see https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS for reference, the part about quoted identifiers), so I believe that this is a very valid user group, especially with how widely spread Django is - and since
sql_metadata claims to support Postgres SQL, even more so!
Within Postgres, it's possible (and sometimes necessary) to put double quotes around table & column names. This causes undesired behavior within sql_metadata:
get_query_columnswon't find any columns, even if they exist.get_query_tablesidentifies the table names (though it doesn't recognize the quotes as being part of the name and will only return the unquoted part).generalize_sqlwill generify both table and column names, which defeats the point of the call.I'm able to work around the table issue by using the result of
get_query_tableto remove the quotes around the table names from the query, so thatgeneralize_sqlwon't eat my table names - but this trick doesn't work for the columns, asget_query_columnsdoesn't recognize them.Reasons why this should be implemented:
sql_metadataclaims to support Postgres SQL, even more so!