pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedproblem with 'copy binary' file format
4+ messages / 2 participants
[nested] [flat]
* problem with 'copy binary' file format
@ 2003-01-21 20:54 john guthrie <jguthrie@psynapsetech.net>
0 siblings, 2 replies; 4+ messages in thread
From: john guthrie @ 2003-01-21 20:54 UTC (permalink / raw)
To: pgsql-interfaces
i am having a problem creating a 'copy binary' input file in c
on my linux box running postgresql 7.2.2. the error message i get is:
ERROR: copy: line 1, pg_atoi: error in "PGBCOPY": can't parse "PGBCOPY"
so it looks to me like the header doesn't match what it should. my
code creates/writes the header like this:
char *bchead = "PGBCOPY\n\377\r\n\0";
unsigned int bcsig = 0x01020304;
unsigned int bcflags = 0x0;
unsigned int bcext = 0x0;
outFile = fopen(tmpfile, "w");
fwrite(bchead,1,12,outFile);
fwrite(&bcsig,1,4,outFile);
fwrite(&bcflags,1,4,outFile);
fwrite(&bcext,1,4,outFile);
when i 'od -c' the created file, i see:
local jguthrie> od -c /tmp/packets.bin
0000000 P G B C O P Y \n 377 \r \n \0 004 003 002 001
0000020 \0 \0 \0 \0 \0 \0 \0 \0 004 \0 377 377
0000034
(this for a 4-field tuple with no rows in the data file).
this all seems to match up with the documentation online:
http://www.postgresql.org/idocs/index.php?sql-copy.html
any help much appreciated.
thanks. john.
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: problem with 'copy binary' file format
@ 2003-01-21 22:19 Tom Lane <tgl@sss.pgh.pa.us>
parent: john guthrie <jguthrie@psynapsetech.net>
1 sibling, 1 reply; 4+ messages in thread
From: Tom Lane @ 2003-01-21 22:19 UTC (permalink / raw)
To: john guthrie <jguthrie@psynapsetech.net>; +Cc: pgsql-interfaces
john guthrie <jguthrie@psynapsetech.net> writes:
> i am having a problem creating a 'copy binary' input file in c
> on my linux box running postgresql 7.2.2. the error message i get is:
> ERROR: copy: line 1, pg_atoi: error in "PGBCOPY": can't parse "PGBCOPY"
And what exactly are you doing with the file after you create it?
pg_atoi shouldn't be invoked at all during COPY BINARY FROM ...
regards, tom lane
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: problem with 'copy binary' file format
@ 2003-01-22 12:41 john guthrie <jguthrie@psynapsetech.net>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 4+ messages in thread
From: john guthrie @ 2003-01-22 12:41 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-interfaces
i agree. i'm not doing anything with the file. i can start up psql, type:
copy binary my_table from 'tmpfile';
and get the exact same error message. the table schema, by the way,
consists of two int4's, a timestamp, and a bytea.
thanks.
john
Tom Lane wrote:
> john guthrie <jguthrie@psynapsetech.net> writes:
>
>>i am having a problem creating a 'copy binary' input file in c
>>on my linux box running postgresql 7.2.2. the error message i get is:
>> ERROR: copy: line 1, pg_atoi: error in "PGBCOPY": can't parse "PGBCOPY"
>
>
> And what exactly are you doing with the file after you create it?
> pg_atoi shouldn't be invoked at all during COPY BINARY FROM ...
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: problem with 'copy binary' file format
@ 2003-01-22 17:10 john guthrie <jguthrie@psynapsetech.net>
parent: john guthrie <jguthrie@psynapsetech.net>
1 sibling, 0 replies; 4+ messages in thread
From: john guthrie @ 2003-01-22 17:10 UTC (permalink / raw)
To: john guthrie <jguthrie@psynapsetech.net>; +Cc: pgsql-interfaces
moron alert - i forgot the 'binary' in the sql i sent to postgresql,
i.e. i used:
copy my_table from 'somefile.bin';
instead of:
copy binary my_table from 'somefile.bin';
only took me a whole day to find this. sheesh!
john
john guthrie wrote:
> i am having a problem creating a 'copy binary' input file in c
> on my linux box running postgresql 7.2.2. the error message i get is:
> ERROR: copy: line 1, pg_atoi: error in "PGBCOPY": can't parse "PGBCOPY"
>
> so it looks to me like the header doesn't match what it should. my
> code creates/writes the header like this:
>
> char *bchead = "PGBCOPY\n\377\r\n\0";
> unsigned int bcsig = 0x01020304;
> unsigned int bcflags = 0x0;
> unsigned int bcext = 0x0;
>
> outFile = fopen(tmpfile, "w");
> fwrite(bchead,1,12,outFile);
> fwrite(&bcsig,1,4,outFile);
> fwrite(&bcflags,1,4,outFile);
> fwrite(&bcext,1,4,outFile);
>
> when i 'od -c' the created file, i see:
> local jguthrie> od -c /tmp/packets.bin
> 0000000 P G B C O P Y \n 377 \r \n \0 004 003 002 001
> 0000020 \0 \0 \0 \0 \0 \0 \0 \0 004 \0 377 377
> 0000034
>
> (this for a 4-field tuple with no rows in the data file).
>
> this all seems to match up with the documentation online:
> http://www.postgresql.org/idocs/index.php?sql-copy.html
>
> any help much appreciated.
>
> thanks. john.
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2003-01-22 17:10 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-01-21 20:54 problem with 'copy binary' file format john guthrie <jguthrie@psynapsetech.net>
2003-01-21 22:19 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-01-22 12:41 ` john guthrie <jguthrie@psynapsetech.net>
2003-01-22 17:10 ` john guthrie <jguthrie@psynapsetech.net>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox