dblink

Copy data between two tables in PostgreSQL using dblink.sql

大憨熊 提交于 2019-12-01 05:48:57
问题 I am using PostgreSQL 9.1. I need to transfer required columns from one table of one database into another table of another database, but not schema. I found that dblink.sql file has to be there in share/contrib . But my contrib folder is empty. Where can I download the dblink.sql file and can execute my query? When I execute the query now it shows an error message: cross database reference is not possible ... Can anyone help me how to transfer the data between two databases? 回答1: After you

Specify dblink column definition list from a local existing type

孤者浪人 提交于 2019-12-01 03:18:31
I am using dblink to move certain data between databases. Everything is save and sound but I am wondering if there is a more convenient way to define the column definition list of a dblink query result. I can do something like this: SELECT * FROM dblink('dbname=remote', 'select * from test') AS t1(id integer, data text); The tables I'm interacting with have the same schema definition in both databases (remote & local). I was thinking of something like: SELECT * FROM dblink('dbname=remote', 'select * from test') AS t1 LIKE public.test; Or: SELECT * FROM dblink('dbname=remote', 'select * from

PostgreSQL的DBLink使用

情到浓时终转凉″ 提交于 2019-11-30 23:59:23
习惯了Oracle的Dblink带来的便捷,我们来看一下PostgreSQL的DBLINK,该工具需要编译安装一下使用,倒也不是很复杂。 DB版本:9.1.3 1.编译安装 [postgres @localhost dblink]$ pwd /home/postgres/postgresql-9.1.3/contrib/dblink [postgres @localhost dblink]$ make make -C ../../src/interfaces/libpq all make[1]: Entering directory `/home/postgres/postgresql-9.1.3/src/interfaces/libpq' make[1]: Nothing to be done for `all'. make[1]: Leaving directory `/home/postgres/postgresql-9.1.3/src/interfaces/libpq' [postgres @localhost dblink]$ make install make -C ../../src/interfaces/libpq all make[1]: Entering directory `/home/postgres/postgresql-9.1.3/src

Oracle sql types over dblink

試著忘記壹切 提交于 2019-11-30 20:59:20
问题 I have two schemas: A and B (Oracle 9). At the A there is a dblink to B. At the B there is a package, that i calls from A. Procedures in B package can returns varying count results and i think that returning a collection is a better way for this reason. create type B.tr_rad as object ( name varchar2(64) ,code number ,vendor number ,val varchar2(255) ,num number ); create type B.tt_rad as varray(256) of B.tr_rad; But from A scheme I cannot use tt_rad type because using SQL-types by dblink is

Is there any shortcut for using dblink in Postgres?

冷暖自知 提交于 2019-11-30 15:44:07
问题 In Postgres, you can link to your other databases using dblink , but the syntax is very verbose. For example you can do: SELECT * FROM dblink ( 'dbname=name port=1234 host=host user=user password=password', 'select * from table' ) AS users([insert each column name and its type here]); Is there any way to do this faster? Maybe pre-define the connections? I noticed that Postgres has a new create foreign table function for connecting to a MySQL database. It has a simpler syntax than dblink .

Is there any shortcut for using dblink in Postgres?

安稳与你 提交于 2019-11-30 14:43:46
In Postgres, you can link to your other databases using dblink , but the syntax is very verbose. For example you can do: SELECT * FROM dblink ( 'dbname=name port=1234 host=host user=user password=password', 'select * from table' ) AS users([insert each column name and its type here]); Is there any way to do this faster? Maybe pre-define the connections? I noticed that Postgres has a new create foreign table function for connecting to a MySQL database. It has a simpler syntax than dblink . Could I use that? In PostgreSQL 8.4 and later, you can use the foreign data wrapper functionality to

Referencing Oracle user defined types over DBLINK?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 07:42:57
问题 I'm working in two different Oracle schemas on two different instances of Oracle. I've defined several types and type collections to transfer data between these schemas. The problem I'm running into is that even though the type have exactly the same definitions (same scripts used to create both sets in the schemas) Oracle sees them as different objects that are not interchangeable. I thought about casting the incoming remote type object as the same local type but I get an error about

postgres dblink escape single quote

99封情书 提交于 2019-11-29 09:36:23
Related Link: String literals and escape characters in postgresql Here is my error: ERROR: type "e" does not exist Here is my query: SELECT * FROM dblink('host=theHostName port=1234 dbname=theDBName user=theUser password=thePassword', E'SELECT field_1, CASE WHEN field_2 IS NOT NULL THEN \'inactive\' ELSE \'active\' END AS field_status FROM the_table ') AS linkresults(field_1 varchar(20),field_2 varchar(8)) If I use double quotes, remove the backslash escape for the single quotes and remove the E before the SELECT statement SELECT * FROM dblink('host=theHostName port=1234 dbname=theDBName user

PostgreSQL数据库dblink和postgres_fdw扩展使用比较

拥有回忆 提交于 2019-11-29 07:40:26
在之前的两篇文章中,章郎虫分别介绍了 dblink 和 postgres_fdw 两个扩展。今天我在这里初略地说下使用dblink和postgres_fdw后的实际感受和区别。 postgres_fdw远程可写功能是9.3版本出来后才新加的,而dblink也可以在以前的postgresql版本中使用。在使用过程中,我把postgres_fdw安装在9.3,dblink安装在9.2.4,而远程连接的都是9.2.4版本的数据库。 首先在安装方面基本都差不多,可以用create extension dblink和create extension postgres_fdw分别安装。 然后比较他们的使用方法。在开始使用dblink之前,首先需要连接远程数据库,然后按照格式编写sql进行查询等操作。这里需要注意,在sql中需要把远程表的字段和类型在本地重新命名,不然sql会报错。这个章郎虫在一开始使用的时候觉得很不方便,而且如果每次查询一张表都要在sql中命名字段和类型其实是很糟糕的,不过幸好可以配置视图把sql“封装”起来。 1 select dblink_connect('myconn', 'host=XXX.XXX.XXX.XXX port=XX dbname=postgres user=myname password=mypassword'); 2 select * from

PostgreSQL: Query has no destination for result data

蹲街弑〆低调 提交于 2019-11-29 03:12:54
I am trying to fetch data from remote db by using dblink through function but getting an error "query has no destination for result data". I am using plpgsql language to do the same. Function : CREATE OR REPLACE FUNCTION fun() RETURNS text AS $$ begin select dblink_connect( 'port=5432 dbname=test user=postgres password=****'); WITH a AS ( SELECT * FROM dblink( 'SELECT slno,fname,mname,lname FROM remote_tbl' ) AS t (slno int, fname text, mname text, lname text) ) , b AS ( INSERT INTO temptab1 SELECT slno, name FROM a ) , c AS ( INSERT INTO temptab2 SELECT slno, name FROM a ) INSERT INTO