Bert_Herngreen wrote:

I have a question regarding external tables. Why is the Timestamp field value padded with 'zero' when it is combined with (var)char fields?

When I create a table with a field of char only (case 1) or timestamp only (case 2) , the field values are as I expected, but when they are combined (case 3) extra zero's are inserted.

Dimitry Sibiryakov answers:

Every value in external tables is aligned. And this alignment depends on data type. Timestamps are aligned to 8 bytes.

For details you can search for thread with subject "Alignment of ISC_TIMESTAMP" in firebird-devel list.

Bert_Herngreen adds:

Maybe I misunderstood your answer, but the Timestamp IS 8 bytes (30 D7 00 00 70 12 EB 14). My question was about the 7 'zero' bytes that are inserted before the TimeStamp field, after the 20's from the char(21). These appear in case 3 only, not in case 1 or case 2.

Ann W. Harrison answers:

Ah, was Dimitry said was not that the timestamp had to be eight bytes long, but that it had to be aligned on an eight byte boundary. The first byte of the timestamp field must be on a byte with an address that is evenly divisible by eight.

As a general rule, data stored in external tables should be stored as char(n) to avoid problems with alignment and file systems that assume that some byte combinations have special semantics.

Like this post? Share on: TwitterFacebookEmail


Related Articles


Author

Firebird Community

Published

Category

Gems from Firebird Support list

Tags