Skip to content

Commit 8f78ccf

Browse files
committed
Simplified example [skip ci]
1 parent 68f377b commit 8f78ccf

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

examples/loading/src/main/java/com/example/Example.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.postgresql.copy.CopyManager;
1111
import org.postgresql.core.BaseConnection;
1212
import org.postgresql.util.ByteConverter;
13-
import org.postgresql.util.PGBinaryObject;
1413

1514
public class Example {
1615
public static void main(String[] args) throws SQLException {
@@ -51,21 +50,13 @@ public static void main(String[] args) throws SQLException {
5150
copyIn.writeToCopy(buffer, 0, 19);
5251

5352
for (int i = 0; i < rows; i++) {
54-
PGBinaryObject[] values = {new PGvector(embeddings.get(i))};
53+
PGvector embedding = new PGvector(embeddings.get(i));
5554

5655
// write row
57-
int pos = 0;
58-
ByteConverter.int2(buffer, pos, values.length);
59-
pos += 2;
60-
for (int j = 0; j < values.length; j++) {
61-
PGBinaryObject value = values[j];
62-
int len = value.lengthInBytes();
63-
ByteConverter.int4(buffer, pos, len);
64-
pos += 4;
65-
value.toBytes(buffer, pos);
66-
pos += len;
67-
}
68-
copyIn.writeToCopy(buffer, 0, pos);
56+
ByteConverter.int2(buffer, 0, 1);
57+
ByteConverter.int4(buffer, 2, embedding.lengthInBytes());
58+
embedding.toBytes(buffer, 6);
59+
copyIn.writeToCopy(buffer, 0, 6 + embedding.lengthInBytes());
6960

7061
// show progress
7162
if (i % 10000 == 0) {

0 commit comments

Comments
 (0)