Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcde5fae

Browse files
committed
>>I confirmed the UNION hack is no longer required. Thanks! Is it too late
>>to change the README in contrib/dblink?>>>> No, I don't think that's a problem. Send a patch.>Here's a (documentation only) patch for the contrib/dblink README.Joe Conway
1 parentba578ae commitcde5fae

File tree

1 file changed

+9
-36
lines changed

1 file changed

+9
-36
lines changed

‎contrib/dblink/README.dblink

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ Outputs
8282

8383
Example usage
8484

85-
select dblink('hostaddr=127.0.0.1 port=5432 dbname=mydb user=postgres password=mypasswd','select f1, f2 from mytable');
85+
select dblink('hostaddr=127.0.0.1 port=5432 dbname=mydb user=postgres password=mypasswd'
86+
,'select f1, f2 from mytable');
8687

8788

8889
==================================================================
@@ -118,44 +119,16 @@ Example usage
118119

119120
==================================================================
120121

121-
NOTE: If you need to provide selection criteria in a WHERE clause, it is necessary
122-
to 'fake' a UNION, e.g.
123-
124-
select
125-
dblink_tok(t1.dblink_p,0) as f1
126-
,dblink_tok(t1.dblink_p,1) as f2
127-
from
128-
(
129-
select dblink(
130-
'hostaddr=127.0.0.1 port=5432 dbname=mydb user=postgres password=mypasswd'
131-
,'select f1, f2 from mytable'
132-
) as dblink_p
133-
union all
134-
select null where false
135-
) as t1
136-
where
137-
dblink_tok(t1.dblink_p,0) = 'mycriteria';
138-
139-
in order to work around an issue with the query optimizer. A more convenient way to approach
140-
this problem is to create a view:
141-
142-
create view myremotetable as
143-
select
144-
dblink_tok(t1.dblink_p,0) as f1
145-
,dblink_tok(t1.dblink_p,1) as f2
146-
from
147-
(
148-
select dblink(
149-
'hostaddr=127.0.0.1 port=5432 dbname=mydb user=postgres password=mypasswd'
150-
,'select f1, f2 from mytable'
151-
) as dblink_p
152-
union all
153-
select null where false
154-
) as t1;
122+
A more convenient way to use dblink may be to create a view:
123+
124+
create view myremotetable as
125+
select dblink_tok(t1.dblink_p,0) as f1, dblink_tok(t1.dblink_p,1) as f2
126+
from (select dblink('hostaddr=127.0.0.1 port=5432 dbname=template1 user=postgres password=postgres'
127+
,'select proname, prosrc from pg_proc') as dblink_p) as t1;
155128

156129
Then you can simply write:
157130

158-
select f1,f2 from myremotetable where f1= 'mycriteria';
131+
select f1,f2 from myremotetable where f1like 'bytea%';
159132

160133
==================================================================
161134

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp