Re: consulta basica

From: "Ing(dot) Marcos Orti­z " <mlortiz(at)uci(dot)cu>
To: Moises Silva <msilva(at)cadebsa(dot)com>
Cc: pgsql-es-ayuda(at)postgresql(dot)org
Subject: Re: consulta basica
Date: 2009-11-12 15:26:53
Message-ID: 4AFC293D.9070805@uci.cu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Moises Silva escribió:
>
> Hola lista, tengo la siguiente duda, como se debe hacer una sentencia
> SQL para manejar 2 tablas en distintas bases de datos.
>
> Se agradece los comentarios y opiniones
>
> Saludos Cordiales
>
> *Moisés Silva Cárdenas
> CADE Informatica
> Plaza Venezuela esq. Loayza No 1401
> La Paz- Bolivia
> ( Telefono: (591-2) 2310390
> 2 Fax: (591-2) 2391139*
> *e-mail: msilva(at)cadebsa(dot)com*
>
>
Esto lo puedes hacer con dblink, conectándote directo a la otra base de
datos, o montando la tabla remota como si fuera otra tabla de tu base de
datos.
Aquí te dejo el ejemplo de la documentación oficial. Espero que te sirva
de algo.

Saludos
**************************************************

select dblink_connect(’dbname=postgres’);
dblink_connect
----------------
OK
(1 row)
select dblink_connect(’myconn’, ’dbname=postgres’);
dblink_connect
----------------
OK
(1 row)
-- FOREIGN DATA WRAPPER functionality
-- Note: local connection must require password authentication for this
to work properl
-- Otherwise, you will receive the following error from
dblink_connect():
--
----------------------------------------------------------------------
-- ERROR: password is required
-- DETAIL: Non-superuser cannot connect if the server does not
request a passwor
-- HINT: Target server’s authentication method must be changed.
CREATE USER dblink_regression_test WITH PASSWORD ’secret’;
CREATE FOREIGN DATA WRAPPER postgresql VALIDATOR postgresql_fdw_validator;
CREATE SERVER fdtest FOREIGN DATA WRAPPER postgresql OPTIONS (hostaddr
’127.0.0.1’, dbn
CREATE USER MAPPING FOR dblink_regression_test SERVER fdtest OPTIONS
(user ’dblink_regr
GRANT USAGE ON FOREIGN SERVER fdtest TO dblink_regression_test;
GRANT SELECT ON TABLE foo TO dblink_regression_test;
\set ORIGINAL_USER :USER
\c - dblink_regression_test
SELECT dblink_connect(’myconn’, ’fdtest’);
dblink_connect
----------------
1899
dblink_connect
OK
(1 row)
SELECT * FROM dblink(’myconn’,’SELECT * FROM foo’) AS t(a int, b text, c
text[]);
a | b | c
----+---+---------------
0 | a | {a0,b0,c0}
1 | b | {a1,b1,c1}
2 | c | {a2,b2,c2}
3 | d | {a3,b3,c3}
4 | e | {a4,b4,c4}
5 | f | {a5,b5,c5}
6 | g | {a6,b6,c6}
7 | h | {a7,b7,c7}
8 | i | {a8,b8,c8}
9 | j | {a9,b9,c9}
10 | k | {a10,b10,c10}
(11 rows)
\c - :ORIGINAL_USER
REVOKE USAGE ON FOREIGN SERVER fdtest FROM dblink_regression_test;
REVOKE SELECT ON TABLE foo FROM dblink_regression_test;
DROP USER MAPPING FOR dblink_regression_test SERVER fdtest;
DROP USER dblink_regression_test;
DROP SERVER fdtest;
DROP FOREIGN DATA WRAPPER postgresql;

--

"For me, the purpose is, at least partly, to have joy. Programmers often
feel joy when they can concentrate on the creative side of programming,
so Ruby is designed to make programmers happy."
Yukihiro Matsumoto (Matz), Creator of the Ruby Language

Ing. Marcos Luís Ortíz Valmaseda
PostgreSQL SysDBA && Rails Developer
BI and DWH Apprentice
Centro de Tecnologías de Almacenamiento y Análisis de Datos (CENTALAD)
Universidad de las Ciencias Informáticas (http://www.uci.cu)

Linux User # 418229

http://www.postgresql.org
http://www.postgresql-es.org
http://www.rubyonrails.org
http://www.ruby-lang.org/es/
http://www.planetrubyonrails.org/
http://www.planetpostgresql.org

In response to

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Moises Silva 2009-11-12 16:04:18 RE: consulta basica
Previous Message Ernesto Quiñones 2009-11-12 15:26:00 Re: consulta basica