0

Here I am trying to assign a "SELECT" query to a specific variable. The select query is retrieving rows from other database table using dblink. For example as shown below:

Example: My try

create or replace function fun(names varchar(60), id bigint) returns void as
$$
Declare
        sql varchar;
Begin
        sql := 'Select * from dblink'('conn','select * from tablex') /* Error occurred here */  
               'where name = ''' || names ||'''';

        raise info '%',sql;

        execute sql,'names varchar(60)',names=names;
end;
$$
Language plpgsql;

ERROR: syntax error at or near "("

2 Answers 2

1

You've messed up your quotimg.

You can use dollar-quoting inside the fumction too.

sql := $SQL$...$SQL$
Sign up to request clarification or add additional context in comments.

Comments

0

Solution: Here is the solution

create or replace function fun(names varchar(60), id bigint) returns void as
$$
Declare
        sql varchar;
Begin
        sql := 'Select * from dblink(''conn','select * from tablex'') 

           where name = ''' || names ||'''';

    raise info '%',sql;

    execute sql,'names varchar(60)',names=names;
end;
$$
Language plpgsql;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.