Parsing COPY ... WITH BINARY

Started by Leonardo M. Raméabout 13 years ago3 messagesgeneral
Jump to latest
#1Leonardo M. Ramé
l.rame@griensu.com

I'm using this:

COPY( select field1, field2, field3 from table ) TO 'C://Program Files/PostgreSql//8.4//data//output.dat' WITH BINARY

To export some fields to a file, one of them is a ByteA field. Now, I
need to read the file with a custom made program.

How can I parse this file?

BTW: I cannot export as CSV, because the binary data is modified when I
do that.

--
Leonardo M. Ramé
Medical IT - Griensu S.A.
Av. Colón 636 - Piso 8 Of. A
X5000EPT -- Córdoba
Tel.: +54(351)4246924 +54(351)4247788 +54(351)4247979 int. 19
Cel.: +54 9 351 6629292

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#2Merlin Moncure
mmoncure@gmail.com
In reply to: Leonardo M. Ramé (#1)
Re: Parsing COPY ... WITH BINARY

On Thu, Jan 31, 2013 at 8:47 AM, Leonardo M. Ramé <l.rame@griensu.com> wrote:

I'm using this:

COPY( select field1, field2, field3 from table ) TO 'C://Program Files/PostgreSql//8.4//data//output.dat' WITH BINARY

To export some fields to a file, one of them is a ByteA field. Now, I
need to read the file with a custom made program.

How can I parse this file?

BTW: I cannot export as CSV, because the binary data is modified when I
do that.

this type of thing is probably better handled with libpq based C
application if you're willing to write one. all this is assuming you
don't want to decode your bytea from encoded format such as hex. why
do you specifically need to dump in binary?

merlin

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#3Leonardo M. Ramé
l.rame@griensu.com
In reply to: Merlin Moncure (#2)
Re: Parsing COPY ... WITH BINARY

On 2013-01-31 17:38:26 -0600, Merlin Moncure wrote:

On Thu, Jan 31, 2013 at 8:47 AM, Leonardo M. Ramé <l.rame@griensu.com> wrote:

I'm using this:

COPY( select field1, field2, field3 from table ) TO 'C://Program Files/PostgreSql//8.4//data//output.dat' WITH BINARY

To export some fields to a file, one of them is a ByteA field. Now, I
need to read the file with a custom made program.

How can I parse this file?

BTW: I cannot export as CSV, because the binary data is modified when I
do that.

this type of thing is probably better handled with libpq based C
application if you're willing to write one. all this is assuming you
don't want to decode your bytea from encoded format such as hex. why
do you specifically need to dump in binary?

merlin

I need to dump in binary because in the dump I have bytea fields. I know
PostgreSql escapes binary data, but I don't want to regenerate it to
"see" in my program.

Anyway, I solved the issue by creating a FreePascal program for parsing
the file, based on the info from here:
http://www.postgresql.org/docs/current/static/sql-copy.html#AEN66736

--
Leonardo M. Ramé
Medical IT - Griensu S.A.
Av. Colón 636 - Piso 8 Of. A
X5000EPT -- Córdoba
Tel.: +54(351)4246924 +54(351)4247788 +54(351)4247979 int. 19
Cel.: +54 9 351 6629292

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general