views:

233

answers:

2

Consider the following text from the PostgreSQL documentation on binary copying:

11-byte sequence PGCOPY\n\377\r\n\0 — note that the zero byte is a required part of the signature. (The signature is designed to allow easy identification of files that have been munged by a non-8-bit-clean transfer. This signature will be changed by end-of-line-translation filters, dropped zero bytes, dropped high bits, or parity changes.)

I can create the rest of the header ok, but what is meant by \377? I thought the largest value you could have in a single byte was 256?

Also, in the example:

0000000   P   G   C   O   P   Y  \n 377  \r  \n  \0  \0  \0  \0  \0  \0
0000020  \0  \0  \0  \0 003  \0  \0  \0 002   A   F  \0  \0  \0 013   A
0000040   F   G   H   A   N   I   S   T   A   N 377 377 377 377  \0 003
0000060  \0  \0  \0 002   A   L  \0  \0  \0 007   A   L   B   A   N   I
0000100   A 377 377 377 377  \0 003  \0  \0  \0 002   D   Z  \0  \0  \0
0000120 007   A   L   G   E   R   I   A 377 377 377 377  \0 003  \0  \0
0000140  \0 002   Z   M  \0  \0  \0 006   Z   A   M   B   I   A 377 377
0000160 377 377  \0 003  \0  \0  \0 002   Z   W  \0  \0  \0  \b   Z   I
0000200   M   B   A   B   W   E 377 377 377 377 377 377

What do those same 377 values represent, as I interprete the format, they shouldn't they be \0's?

If any one could help with the rest of the format, it would be appreciated. I could cheat and use the CVS database copy, but with the number of rows I need to copy (in the millions) I understand the binary format would have many advantages in speed over the CVS one.

+2  A: 

The \377 is octal - its decimal value is 255. Was there anything else about the format which was specifically confusing you?

Jon Skeet
that answers a LOT, especially as to why for example '013' was the length a the value, but was actually less than that in length. This makes lots more sense. Thanks.
Ash
+1  A: 

Basically you will not get any significant speedup by using the binary format. It has different benefits, but loading the data faster is not really one of them.

Just use standard csv and COPY command and you should be fine.

depesz