0

In sql-server, one can connect to the master db and write a statement in the below syntax to query any table:

SELECT * FROM [database].[dbo].[table]

I've ran some google searches for "postgres full table address" and "postgres object hierarchy" but to no avail. See this question for more on how this is done in sql-server.

Are operations like this possible in Postgres (I'm running version 9.3)?

  • If so, please explain how with a code example.

  • If not, please explain why not.

Community
  • 1
  • 1
nicholsonjf
  • 971
  • 2
  • 11
  • 21

1 Answers1

1

From Table Expressions in the manual:

A table reference can be a table name (possibly schema-qualified), or a derived table such as a subquery, a table join, or complex combinations of these

That's it. No database name is allowed.

If a session has to refer to tables in a different database than it's connected to, it should use a dblink, or a foreign table through a data wrapper. In PostgreSQL, the databases within the same instance are deeply insulated from each other. When different namespaces are needed, schemas are used as opposed to databases.

Daniel Vérité
  • 58,074
  • 15
  • 129
  • 156