You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Remapping Postgres minified aliases can result in data loss #15646
As of right now the way minified aliases are remapped can actually cause data corruption in Postgres. This I believe is due to the idea that we're using RegExp's to replace strings present in the generated minified query.
if(options?.minifyAliases&&this.options.includeAliases){for(const[alias,original]of_.toPairs(this.options.includeAliases)// Sorting to replace the longest aliases first to prevent alias collision.sort((a,b)=>b[1].length-a[1].length)){constreg=newRegExp(_.escapeRegExp(original),'g');sql=sql.replace(reg,alias);}}
The above I think is for remapping aliases for fields and the same is also done for remapping joins that are minified, which also produces the same problem.
No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.
Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.
No the entire concept of using a regexp to modify SQL must be removed, it's inherently unsafe. The question is: what will it break and how can we provide a better solution?
Hey @ephys sorry for taking long finally got work done and can again put in some time here, I came up with an approach could be naive but I think I can improve more on it!
So I am thinking in the following terms;
We make a Map that keeps track of a unique number (can be just incrementing) and a string with it for example
{"0": "a_huge_string_that_was_given_to_me"}
Now I am thinking of keeping incrementing them even if we receive same string twice so let's say we got this query
Since this Map will be available globally I will create a function that will traverse the string and each time I encounter these numbers or any specific identifier that we assign (I am thinking like those numbers but we can be specific) we just call this function and that function gets the number and gets replaced by that original column name!
Does this make sense or is not a good way of approaching it?
If you're considering transforming the final SQL but with an alternative approach, that's not going to work. You'd need to use an actual SQL parser for this, I don't recommend it
Sorry @ephys I think I wasn't able to explain it properly but I created a quick Repl here to show the gist of it, it certainly can be improved I am still thinking on it!
Activity
frostzt commentedon Mar 9, 2023
@ephys so I am thinking of excluding fields that are in the
whereclause. Is that right? To be honest need a little enlightenment here 😅ephys commentedon Mar 9, 2023
No the entire concept of using a regexp to modify SQL must be removed, it's inherently unsafe. The question is: what will it break and how can we provide a better solution?
frostzt commentedon Mar 21, 2023
Hey @ephys sorry for taking long finally got work done and can again put in some time here, I came up with an approach could be naive but I think I can improve more on it!
So I am thinking in the following terms;
I am gonna loop over store
a_huge_string_that_was_given_to_melike thisDoes this make sense or is not a good way of approaching it?
ephys commentedon Mar 21, 2023
To be honest I don't think I understood your plan
If you're considering transforming the final SQL but with an alternative approach, that's not going to work. You'd need to use an actual SQL parser for this, I don't recommend it
frostzt commentedon Mar 22, 2023
Sorry @ephys I think I wasn't able to explain it properly but I created a quick Repl here to show the gist of it, it certainly can be improved I am still thinking on it!