从 PostgesSQL 中的变量创建 dblink 连接字符串

问题描述 投票:0回答:1
DO $$ 
DECLARE 
_host TEXT := 'localhost';
_port TEXT := '5432';
_user TEXT := 'postgres';
_pass TEXT := 'postgres';
_db TEXT := 'schema';
BEGIN 
CREATE OR REPLACE VIEW companies AS
SELECT
    id
FROM
    dblink(
        'postgresql://' || _user || ':' || _pass || '@' || _host || ':' || _port || '/' || _db,
        'select id from company'
    ) AS t1(
        id TEXT
    );

DROP VIEW IF EXISTS companies CASCADE;
COMMIT;
END $$;

我想从下面的变量创建字符串配置

'postgresql://postgres:postgres@localhost:5432/schema'
postgresql dblink
1个回答
0
投票

我想从下面的变量创建字符串配置

_host TEXT := 'localhost';

_端口文本 := '5432';

_user TEXT := 'postgres';

_pass TEXT := 'postgres';

_db TEXT := '模式';

=> 'postgresql://postgres:postgres@localhost:5432/schema'

© www.soinside.com 2019 - 2024. All rights reserved.