ИА
coalesce(ds.id, ds2.id) id,
coalesce(ds.name, ds2.name) "name",
dc.owner_id, dc.owner_type,
coalesce(dc2.dbclass, dc.dbclass) dbclass,
coalesce(dc2.server, dc.server) "server", coalesce(dc2.port, dc.port) port
from data_connections dc
left join datasources ds ON dc.dbname = ds.repository_url AND ds.connectable = true
left join datasources ds2 on dc.datasource_id = ds2.id
left join data_connections dc2 on ds.id = dc2.datasource_id
where coalesce(dc2.server, dc.server) = '127.0.0.1'

