Shashi Singh
Shashi Singh

Reputation: 1

How to Perform Insert Operation with DbLink in Postgres

I am tying to perform insert with dblink in postgres but it is throwing error column "Test" does not exist

Select * 
from dblink('host=localhost user=postgres password=Test dbname=wb',
            'Insert Into tblProducts(AccountNumber,AccountProductNumber,supplierproductnumber)
             Values( 2012, 2022,'Test') Returning ProductNumber'
     ) AS tblProducts(ProductNumber integer)

Upvotes: 0

Views: 103

Answers (1)

Frank Heikens
Frank Heikens

Reputation: 127086

You have to escape the quotes within the payload, using an additional quote '' (two single quotes):

Select * 
from dblink('host=localhost user=postgres password=Test dbname=wb',
            'Insert Into tblProducts(AccountNumber,AccountProductNumber,supplierproductnumber)
             Values( 2012, 2022,''Test'') Returning ProductNumber'
     ) AS tblProducts(ProductNumber integer);

Upvotes: 1

Related Questions