Yeah. Definitely went down a fun rabbit hole on that separate code paths issue.
Perhaps, rather than trying to fix this automatically, we should
leave it to the user. We could invent another import option that
says what to translate "default" to, with the default being,
uh, "default".
I like this idea. One suggestion might be to do a check for the remote LC_COLLATE and the local LC_COLLATE at the beginning of an IMPORT FOREIGN SCHEMA call and at least raise a warning if the default collations do not match. That wouldn't break anything, but at least would notify the user that something bad could be happening and pointing them to that variable.
Actually, instead of an import option, this might make more sense as an option on the foreign server, add a default_collation_mapping option for the foreign server and raise a warning either at foreign server creation time or at import foreign schema time (probably the latter as I don't think we actually connect to the remote when we create the foreign server).
D