according to the docs selecting a REGXP will always produce a boolean (match or non match) but I’m trying to get the result, if it’s a match, meaning if I’m doing…
select file_id REGEXP '^\d{10}' from my_table;
What I want back is not false or true but false or the actual 10 digits that start file_id.
Am I missing something? or is this really how mySQL has implemented regexp?!
I realize that in my case, I can use SUBSTR, but now I’m just curious why they would have deviated from the prescribed norm of how regexp matching works everywhere else.
In answer to your question, “is this really how MySQL has implemented regexp?” the answer is yes. It simply returns a boolean on success or failure to match.
In answer to your question, “why they would shave deviated form the prescribed norm”, the answer is that it is more useful in queries to have boolean returns, since you are more often testing for the presence of something, not extracting something, based on a pattern. Extracting things is more often done using procedural languages, not relational databases.
To do what you want it to do, you might want to write a stored procedure that does the necessary string manipulation.