Here I need to check condition within the select statement using dblink. The following example having more details as shown below:
Example:
create or replace function dblink_fun(ID bigint) returns void as
$$
Begin
perform dblink_connect('hostaddr=127.0.0.0 port=5432 dbname=db user=postgres password=***');
With x AS ( Select "EmpID","EmpNo","Slno","Edate"
From tabletest c
Where c."EmpID" = ID
)
, y AS
( Select Row_Number() over ( Partition by "Slno" order by "DateOfJoinig" Desc) AS Rnk,
"SName","Slno","DateOfJoining","TimeOfJoining","Address",Ranked."empID"
from dblink('select
"Slno"',
( case when "FirstName" is null then ''
else "FirstName" end || '' ||
Case When "MiddleName" is null then ''
else "LastName" end || '' ||
) AS name ,
( Case When "Address1" is null then ''
else "Address1" end || '' ||
Case When "Address2" is null then ''
else "Address2" end || '' ||
) AS address,
"JoinigDate", "TimeofJoin", "EmpID" From "remote_table"
inner join "x" on x."Slno" = "Slno"
Where x."Edate" >= (
Case When "DateOfJoinig" is null then '1900-01-01' else "DateOfJoinig" end' /*error near 1900 */
) Ranked
)
perform dblink_disconnect();
end;
$$
Language plpgsql;
ERROR: syntax error at or near "1900"
...s are important. Show the whole thing, please, or a self-contained example that has the problem where you've trimmed it down to show just the problem.