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

Improve table prefix detection #1

Open
pryazhnikov opened this issue Jul 4, 2018 · 1 comment
Open

Improve table prefix detection #1

pryazhnikov opened this issue Jul 4, 2018 · 1 comment

Comments

@pryazhnikov
Copy link
Owner

pryazhnikov commented Jul 4, 2018

Right now tables.sql has this condition:

SUBSTRING_INDEX(TABLE_NAME, "_", 1)

This condition works well against table names like 'user_photos_123', but fails against other variations:

SELECT SUBSTRING_INDEX("Users123", "_", 1);
# => Users123

SELECT SUBSTRING_INDEX("UserPhotos123", "_", 1);
# => UserPhotos123

SELECT SUBSTRING_INDEX("user_photos_123", "_", 1);
# => user
@pryazhnikov
Copy link
Owner Author

There is an obvious solution at MySQL 8.0:

## "TABLE_NAME_123" => "TABLE_NAME_"
SELECT REGEXP_REPLACE("TABLE_NAME_123", "[0-9]+$", "");

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

No branches or pull requests

1 participant