Since you mentioned Gary Moore and Santana, there is a certain technique for this. A comment below stated Peter Green's Supernatural. That's a perfect example of endless sustain.
It's something that is very hard or nearly impossible to emulate in your bedroom. How these guys get such sustain is through feedback. Musical controlled feedback, not the kind where some guy is using way way too much gain and then squeeky piercing sounds start coming out.
The technique is to have your amp at a very very loud volume, and also a certain amount of gain. There is a certain spot called the sweet spot where the guitar has to be, (some musicians like Neil Young mark that spot on stage when they play) and if you hold a note, it will feedback into endless sustain, it could go on literally forever. The type I love is when the feedback moves into the higher octaves. Sometimes when you watch videos of guitarist you see them turn around and face their guitars to the amps, they are trying to achieve that sort of controlled feedback. This is pretty much the old school method.
Today you can create artificial endless sustain. Stuff like the EHX Freeze, the E-bow, Fernandes sustainer. A lot of cool stuff really. This is a much better route since the old school method is pretty impractical.
Anyway a compressor isn't what you need for added sustain. People who buy compressors because they want more sustain don't know what a compressor is for and they think gear is a shortcut to improving technique.