Unix Technical Forum

Binary COPY for psql

This is a discussion on Binary COPY for psql within the Pgsql Patches forums, part of the PostgreSQL category; --> The attached patch enables psql to copy binary data in and out. Regards, Andreas Index: src/bin/psql/copy.c ================================================== ================= RCS ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Patches

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-18-2008, 01:39 AM
Andreas Pflug
 
Posts: n/a
Default Binary COPY for psql

The attached patch enables psql to copy binary data in and out.

Regards,
Andreas

Index: src/bin/psql/copy.c
================================================== =================
RCS file: /projects/cvsroot/pgsql/src/bin/psql/copy.c,v
retrieving revision 1.60
diff -u -r1.60 copy.c
--- src/bin/psql/copy.c 5 Mar 2006 15:58:51 -0000 1.60
+++ src/bin/psql/copy.c 25 May 2006 15:17:58 -0000
@@ -284,9 +284,10 @@

fetch_next = true;

- /* someday allow BINARY here */
if (pg_strcasecmp(token, "oids") == 0)
result->oids = true;
+ else if (pg_strcasecmp(token, "binary") == 0)
+ result->binary = true;
else if (pg_strcasecmp(token, "csv") == 0)
result->csv_mode = true;
else if (pg_strcasecmp(token, "header") == 0)
@@ -442,8 +443,6 @@
initPQExpBuffer(&query);

printfPQExpBuffer(&query, "COPY ");
- if (options->binary)
- appendPQExpBuffer(&query, "BINARY ");

appendPQExpBuffer(&query, "%s ", options->table);

@@ -480,6 +479,9 @@
appendPQExpBuffer(&query, " WITH NULL AS '%s'", options->null);
}

+ if (options->binary)
+ appendPQExpBuffer(&query, " BINARY");
+
if (options->csv_mode)
appendPQExpBuffer(&query, " CSV");

@@ -622,7 +624,7 @@

if (buf)
{
- fputs(buf, copystream);
+ fwrite(buf, 1, ret, copystream);
PQfreemem(buf);
}
}
@@ -686,6 +688,21 @@
else
prompt = NULL;

+ if (!prompt)
+ {
+ int buflen;
+
+ while ((buflen = fread(buf, 1, COPYBUFSIZ, copystream)) > 0)
+ {
+ if (PQputCopyData(conn, buf, buflen) <= 0)
+ {
+ OK = false;
+ copydone = true;
+ break;
+ }
+ }
+ }
+ else
while (!copydone)
{ /* for each input line ... */
if (prompt)


---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-18-2008, 01:40 AM
Tom Lane
 
Posts: n/a
Default Re: Binary COPY for psql

Andreas Pflug <pgadmin@pse-consulting.de> writes:
> The attached patch enables psql to copy binary data in and out.


Applied with revisions.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:16 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com