EDIT: This is not ideal but it should work if you don't need to do it in the UI. You can open and edit the qgs project files as the connection strings and sql string is stored in there. When using postgres search for <datasource>
in the qgs project file. As the file is xml you can just edit the string and reload the project file.
via Python:
You can kind of get half way there using the python APIs although you need to set the layers providers datasource and also the datasource on the layer itself, which you can't do......yet.
from PyQt4.QtCore import QString
qgis.console.clearConsole()
layer = qgis.utils.iface.mapCanvas().currentLayer()
pro = layer.dataProvider()
print "The old providers datasource"
pro.dataSourceUri()
print "Set the providers datasource"
pro.setDataSourceUri(QString(u'dbname=\'postgis\' host=localhost port=5432 user=\'postgres\' key=\'property_no\' table="(SELECT \\"t_0\\".\\"property_no\\", \\"t_0\\".\\"SP_GEOMETRY\\" FROM \\"public\\".\\"Property\\" AS \\"t_0\\"\n)" (SP_GEOMETRY) sql='))
print "Print out the new datasource"
pro.dataSourceUri()
print("Reloading data")
pro.reloadData()
layer.reload()
print "The layers datasource"
layer.publicSource()
print "God dam! It's still the old one"
It seems from the code there are two places where there is a datasource string; in the provider and in the layer. The layers datasource is not sync to the providers datasource, so you can update the provider but the layer still knows nothing.
I'll have a chat to the devs to see if there is a reason why we couldn't sync the two together.