sql select thru multiple postgres databases - sql

is there a way to create a select statement that would retrieve data from multiple database in postgre?
i was thinking it would be something like this:
select * from dbname1.table1, dbname2.table2 where dbname1.table1.column1 = dbname2.table2.column1

Have a look at the "dblink" contrib module.
OTOH it's possible that you treat the databases in a PostgreSQL cluster as equivalent to the databases in... let's say MySQL. Which is incorrect - the PostgreSQL databases contain schemas and those are the equivalent of the databases in MySQL.

From here:
It is not possible to access more than
one database per connection.
Update: but see Milen's answer.

Related

Do Ingres and Vectorwise Databases support functionality similar to TRUNCATE table in SQL Server? If so, what is the syntax?

Trying to find if there is something similar to TRUNCATE TABLE in these 2 database systems.
MODIFY mytable TO TRUNCATED
is the equivalent SQL for Ingres/Vector/ActianX

is it possible to apply a query in hibernate which uses two databases?

I have two different databases (on same server) and i want to join tables across databases. I am using Hibernate, is it possible to create a query in hibernate which can join two tables in those databases?
Hibernate will create an SQL query for your HQL or Criteria query and this SQL will be sent through jdbc to the database. This means that hibernate does not support for what you are trying to do.
However, you can achieve the same result in some cases. Some databases give you the option to create an alias for a table that resides in a different database. So you will be able to write an SQL query that joins the two tables and execute it on the database.
We are doing that with DB2.
If you can do that, it depends on your database.
I guess, that it would impossible if you have two different databases (example DB2 and MySQL) but if both databases are of the same vendor, then maybe it's achievable.
You should try to find more info in you database server's documentation.

how to obtain a list of schemas in intersystems cache?

I'm connecting to a Caché database using the ODBC driver, and I want to do a query to obtain a list of schemas. In Microsoft SQL Server I can use a query like this:
SELECT * FROM INFORMATION_SCHEMA.SCHEMATA
How can I do this in Caché? I'm also using ADO.NET schema collections, but the schemas don't seem to be available there.
The schema %dictionary has the tables you are looking for. You could select from %dictionary.compiledclass

Data from 4 different database

I need to get data from 3 different databases on one event command. Can anybody tell me any efficient way besides I am querying to all three different database servers in a row:-
Server 1 : Select * from ....
Server 2 : Select * from.....
and so on...
Thanks very much
Seeing as the question is marked TSQL:
Install the providers for the 'other' databases.
In SQL Server 2005, create a linked server to each database, and then simply query as though the 'other' databases were SQL Server databases.
If the databases are on the same server instance, they can be queried in the format "database_name.table_name.column_name" otherwise I would use Mitch's answer (linked servers can be queried in the format "server_name.database_name.table_name.column_name")

Listing all tables in a database

Is there a SQL command that will list all the tables in a database and which is provider independent (works on MSSQLServer, Oracle, MySQL)?
The closest option is to query the INFORMATION_SCHEMA for tables.
SELECT *
FROM INFORMATION_SCHEMA.Tables
WHERE table_schema = 'mydatabase';
The INFORMATION_SCHEMA is part of standard SQL, but not all vendors support it. As far as I know, the only RDBMS vendors that support it are:
MySQL
PostgreSQL
Microsoft SQL Server 2000/2005/2008
Some brands of database, e.g. Oracle, IBM DB2, Firebird, Derby, etc. have similar "catalog" views that give you an interface where you can query metadata on the system. But the names of the views, the columns they contain, and their relationships don't match the ANSI SQL standard for INFORMATION_SCHEMA. In other words, similar information is available, but the query you would use to get that information is different.
(footnote: the catalog views in IBM DB2 UDB for System i are different from the catalog views in IBM DB2 UDB for Windows/*NIX -- so much for the Universal in UDB!)
Some other brands (e.g. SQLite) don't offer any queriable interface for metadata at all.
No. They all love doing it their own little way.
No, the SQL standard does not constrain where the table names are listed (if at all), so you'll have to perform different statements (typically SELECT statements on specially named tables) depending on the SQL engine you're dealing with.
If you are OK with using a non-SQL approach and you have an ODBC driver for the database and it implements the SQLTables entry-point, you possibly might get the information you want!
pjjH
details on the API at:
http://msdn.microsoft.com/en-us/library/ms711831.aspx