void writeToDBBinary(struct SAMPLE *points, char *fileName, int fileType) { //my process result is in input parameter struct SAMPLE
PGconn *conn = NULL;
PGresult *pgrst = NULL;
conn = PQsetdbLogin(host, port, options, tty, dbname, user, password);
char *buf = (char*) malloc(1024 * sizeof (char));
unsigned short fieldNum = 21;
char *sendHeader = "PGCOPY\n\377\r\n\0";
unsigned int zero = '\0';
struct strBuffer strBuf;
strBuf.data = buf;
strBuf.len = MAX_BUFFER;
int i = 0;
int j = 0;
int k = 0;
struct SAMPLE *tSample;
if (fileType) { //insert reference file
//total 19 column, not include cid
sprintf(sqlBuf, "COPY %s(\
starid,crossid,catid,magnorm,ra,dec,background,classstar,ellipticity,flags,mag,mage,fwhm,pixx,pixy,thetaimage,vignet,\
magcalib,magcalibe,pixx1,pixy1 \
)FROM STDIN WITH BINARY", match_table);
pgrst = PQexec(conn, sqlBuf);
if (PQresultStatus(pgrst) == PGRES_COPY_IN) {
strBuf.cursor = 0;
memcpy(strBuf.data, sendHeader, 11);
strBuf.cursor += 11;
memcpy(strBuf.data + strBuf.cursor, (char*) &zero, 4);
strBuf.cursor += 4;
memcpy(strBuf.data + strBuf.cursor, (char*) &zero, 4);
strBuf.cursor += 4;
tSample = points->next;
while (tSample) {
addInt16(&strBuf, fieldNum); //column number, when add or delete colume, must change this number
addInt64(&strBuf, tSample->id);
addInt64(&strBuf, tSample->crossid);
addInt64(&strBuf, catid);
addFloat8(&strBuf, -1.0);
addFloat8(&strBuf, tSample->alpha);
addFloat8(&strBuf, tSample->delta);
addFloat8(&strBuf, tSample->background);
addFloat8(&strBuf, tSample->classstar);
addFloat8(&strBuf, tSample->ellipticity);
addFloat8(&strBuf, tSample->flags);
addFloat8(&strBuf, tSample->mag);
addFloat8(&strBuf, tSample->mage);
addFloat8(&strBuf, tSample->fwhm);
addFloat8(&strBuf, tSample->pixx);
addFloat8(&strBuf, tSample->pixy);
addFloat8(&strBuf, tSample->thetaimage);
addFloat8(&strBuf, tSample->vignet);
addFloat8(&strBuf, tSample->magcalib);
addFloat8(&strBuf, tSample->magcalibe);
addFloat8(&strBuf, tSample->pixx);
addFloat8(&strBuf, tSample->pixy);
int copydatares = PQputCopyData(conn, strBuf.data, strBuf.cursor);
//if(i >5) break;
i++;
tSample = tSample->next;
strBuf.cursor = 0;
}
PQputCopyEnd(conn, NULL);
} else {
printf("can not copy in!\n");
}
PQclear(pgrst);
so i am sure it's worthy to implement binarycopy in monetdb.