I'm currently using double precision fields in my postgres database.
I want them over to numeric fields.
While testing this change in our software I ran into an odd situation.
If I try using a pgQuery to retrieve a double equal to the delphi MaxDouble it returns an incorrect value.
For an example take this table structure
Code: Select all
CREATE TABLE public.testtable
(
idfield integer NOT NULL DEFAULT nextval('testtable_idfield_seq'::regclass),
testnumeric numeric,
CONSTRAINT testtable_pkey PRIMARY KEY (idfield)
)
WITH (
OIDS=FALSE
);
ALTER TABLE public.testtable
OWNER TO postgres;
Code: Select all
var query: TPgQuery;
id: Integer;
begin
query := TPgQuery.Create(nil);
try
query.Connection := PgConnection1; // Connection to database with newly created table
query.Sql.Text := 'INSERT INTO testtable (testnumeric) values (:val) returning idfield';
query.ParamByName('val').Value := MaxDouble;
query.Open;
id := query.FieldByName('idfield').AsInteger;
query.Close;
query.Sql.Text := 'SELECT testnumeric FROM testtable WHERE idfield = :id';
query.ParamByName('id').Value := id;
query.Open;
if(query.FieldByName('testnumeric').AsFloat = MaxDouble) then
begin
ShowMessage('Success');
end
else
begin
ShowMessage('Failed');
end;
finally
query.Free;
end;
end;
If I check the database the value does seem to be stored correctly in there, so it seems to be a problem with retrieving it.
Coincidentally the same code does show Success if we change the testnumeric field to a double precision field.
Is this a know problem, am i doing something wrong or neither?