for (;;) {

	// collecting data until buffer is filled

	PGresult* res;

	// wait until connection is ready
	while ((res = PQgetResult(conn)) != 0) {
		const ExecStatusType s = PQresultStatus(res);
		// errors handling
		PQclear(res);
		usleep(1000);
	}

	// established COPY
	res = PQexec(conn, query);
	status = PQresultStatus(res);
	if (status == PGRES_COPY_IN) {

		// send data
		const int copy_result = PQputCopyData(conn, buffer, size);
		if (res == 1) {
			const int copy_end_result = PQputCopyEnd(conn, NULL);
			// errors handling
		}
	}

	PQclear(res);
}
