I work with Potgresql. Any heavy queries I build with stored functions. And what I found. Some times If I join function with table(view), some fields have the wrong datatype. Like this
Code: Select all
CREATE OR REPLACE FUNCTION p_test ()
RETURNS TABLES(
A bigint,
B integer
)
$body$
DECLARE
...
BEGIN
...
return;
END;
$body$
LANGUAGE 'plpgsql'
VOLATILE
CALLED ON NULL INPUT
SECURITY INVOKER
COST 100 ROWS 1000;
CREATE TABLE test_table (
A integer,
B varchar
) WITHOUT OIDS;
Code: Select all
select p.a, p.b
from p_test() p
join test_table t on p.b = t.a
so go to source "ZDbcResultSetMetadata.pas"
Code: Select all
procedure TZAbstractResultSetMetadata.LoadColumn(ColumnIndex: Integer;
ColumnInfo: TZColumnInfo; SelectSchema: IZSelectSchema);
var
I: Integer;
FieldRef: TZFieldRef;
TableRef: TZTableRef;
Found: Boolean;
begin
{ Initializes single columns with specified table. }
FieldRef := SelectSchema.LinkFieldByIndexAndShortName(
ColumnIndex, ColumnInfo.ColumnLabel);
ReadColumnByRef(FieldRef, ColumnInfo);
if ColumnInfo.ColumnName <> '' then
Exit;
{ Initializes single columns without specified table. }
I := 0;
Found := False;
while (ColumnInfo.ColumnName = '') and (I < SelectSchema.TableCount)
and not Found do
begin
TableRef := SelectSchema.Tables[I];
if Assigned(FieldRef) then
Found := ReadColumnByName(FieldRef.Field, TableRef, ColumnInfo)
else
Found := ReadColumnByName(ColumnInfo.ColumnLabel, TableRef, ColumnInfo);
Inc(I);
end;
end;
why? because we work with function and procedure "ReadColumnByRef" not change "ColumnInfo.ColumnName" (request for metadata for function returns an empty query)
fix this problem after lines
Code: Select all
if ColumnInfo.ColumnName <> '' then
Exit;
//==fix problem with function/procedure===========
if Assigned(FieldRef) and Assigned(FieldRef.TableRef) then
Exit;
//====================================
testing on 6.6 and 7.0
wanted to include this patch in the next version
Thanks, All