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.

4
  • it's the same, database.schema.table. did you even try it before posting? Commented Feb 3, 2014 at 18:12
  • Yup, I tried and receive the following error: ERROR: cross-database references are not implemented: "DBname.public.TABLEname" Commented Feb 3, 2014 at 18:48
  • Also, why the down vote? I know this is a rookie question, but for someone new to Postgres I think it's a valid thing to ask here. Commented Feb 3, 2014 at 18:50
  • not my down vote. If you've tried something and received an error, it's best to include that in your post. Commented Feb 3, 2014 at 18:53

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.