Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nEtPJ-00084X-KH for pgsql-sql@arkaria.postgresql.org; Tue, 01 Feb 2022 13:41:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nEtPI-0001AQ-Fi for pgsql-sql@arkaria.postgresql.org; Tue, 01 Feb 2022 13:41:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nEtPH-00019h-QU for pgsql-sql@lists.postgresql.org; Tue, 01 Feb 2022 13:41:16 +0000 Received: from mail-ua1-x935.google.com ([2607:f8b0:4864:20::935]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nEtPE-0000kw-6v for pgsql-sql@lists.postgresql.org; Tue, 01 Feb 2022 13:41:15 +0000 Received: by mail-ua1-x935.google.com with SMTP id c36so13777850uae.13 for ; Tue, 01 Feb 2022 05:41:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joeconway.com; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to:content-transfer-encoding; bh=EM6RC9RA2k1wy8UuV+J1PyPrfe0wg6lNQ6I4nHTlujo=; b=XUYY4jt9N6UMxwd525e6Abf2luBxhoflKJJNdixGUiAtNI9ll2ljlLu4FMutEnvgW3 Doay6Ovqtuf01dyON3o1IP2l3LLUaKcBX7RniG6ebdpHJ0dHLG4A64prucIhWPdtdta7 +R/rj3Ca3HtFrKAoasvEa5PSyyNenRAskiq6pJvKuEZ5ZJxxBRaC1G1nZUWX7xtMtL8A rj11+xlgl1GHsLChdxfSSlaNmxZPEi/HlIqFITEmkugmCWOd5pFSs1TqLQ74VW6kHq+K vqRkde3McJYHKhdTy7uyVsKy2ZzP+ZBfFsUqu/3MiHiayBSBmP6SfeoeV7Gk2mGnFf7g Qw4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=EM6RC9RA2k1wy8UuV+J1PyPrfe0wg6lNQ6I4nHTlujo=; b=LyOCh3NGDlS/S7qgU3P//d8sSe4N2efk+kLs4hzTRHeaYHI9/nh07RHZoBmFN7Jcxl NV2cPbihSFWNMnzV0+zoPT1IRKRwRK8FL3AbRh8yHTq6XzdmOB9VX1hTx6XTi/tMmmXJ v76vlo/tdJ2qazPVtFZ2h5N3flX4grNkI8m3ND9e2eIDC3KsCUPNLrKBD229S0ox8wM0 2k8tLACcE+cB7NJEljKkPOcF3wHEq6egLuZmbhMEEd84m0wlNUx30O8BN2gMAlEZ7Au+ lKZogpvUXKbDGWYIgY+S3LD1rv/PtixV/5nb65krHQ5giDdkutkBZTI166ZduDdSSv8A eRNA== X-Gm-Message-State: AOAM530oTSIvkA+PZEJ+70uhCGSKza2f/Sfmgxvx0QLRh/WdW6Vit7l6 U9dzoObGRvxhoAHCwK0Z0mlnpQ== X-Google-Smtp-Source: ABdhPJzky2dNtXloJvm3Umz3GEUEgABnFH3All1qLnhDs/QMJPxL56/2PUfzolYFmzuUeyMSmv2+Cw== X-Received: by 2002:ab0:1d93:: with SMTP id l19mr9892737uak.32.1643722870024; Tue, 01 Feb 2022 05:41:10 -0800 (PST) Received: from [192.168.4.41] (072-017-018-098.res.spectrum.com. [72.17.18.98]) by smtp.gmail.com with ESMTPSA id r14sm4715631vke.26.2022.02.01.05.41.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Feb 2022 05:41:09 -0800 (PST) Message-ID: Date: Tue, 1 Feb 2022 08:41:08 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: How can i pass variable in dblink_connect_u ? Content-Language: en-US To: aditya desai , pgsql-sql References: From: Joe Conway In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2/1/22 05:42, aditya desai wrote: > Hi All, > how can I pass variables in dblink_connect_u ? > > Current code hardcoded DB name: > perform * from dblink_connect_u('myconn','dbname=mydb'); > > Expected: > databasename=current_database(); > perform * from dblink_connect_u('myconn','dbname=databasename'); > > databasename is getting considered as text. Correct, it is a string literal. So just create the string literal using string manipulation functionality -- e.g.: SELECT dblink_connect_u('myconn','dbname=' || current_database()); dblink_connect_u ------------------ OK (1 row) HTH, Joe -- Crunchy Data - http://crunchydata.com PostgreSQL Support for Secure Enterprises Consulting, Training, & Open Source Development