I have this SQL function in postgresql-9.3.2-1-windows-x64:
Code: Select all
CREATE OR REPLACE FUNCTION fnk_create_table(prm_name varchar, prm_surname varchar)
RETURNS TABLE(clm_name varchar(3), clm_surname varchar(6)) AS
$BODY$
BEGIN
RETURN QUERY select CAST(prm_name AS varchar(3)) as clm_name, CAST(prm_surname as varchar(6)) as clm_surname;
END;$BODY$
LANGUAGE plpgsql VOLATILE
COST 1 SECURITY DEFINER ROWS 1;
ALTER FUNCTION fnk_create_table(varchar, varchar) OWNER TO postgres;
GRANT EXECUTE ON FUNCTION fnk_create_table(varchar, varchar) TO postgres;
Code: Select all
select * from fnk_create_table('Albert', 'Einstein ');
Code: Select all
clm_name clm_surname
Alb Einste
Add this code in OnFormCreate event:
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
begin
ZConnection1.HostName := 'localhost';
ZConnection1.User := 'postgres';
ZConnection1.Password := 'your_password_here';
ZConnection1.Database := 'postgres';
ZConnection1.Protocol := 'postgresql-9';
ZConnection1.Connected := True;
ZQuery1.Connection := ZConnection1;
ZQuery1.SQL.Add('select * from fnk_create_table(''Albert'', ''Einstein'');');
ZQuery1.Open;
DataSource1.DataSet := ZQuery1;
DBEdit1.DataSource := DataSource1;
DBEdit1.DataField := 'clm_name';
end;
Code: Select all
ZQuery1.FieldByName('clm_name').SetFieldType(TFieldType.ftString);
DBEdit1.Field.SetFieldType(TFieldType.ftString);
Windows 7 x64, ZEOSDBO-7.1.2-stable, Delphi XE2.