0

I wrote a java program to create a binary file compatible with PostgreSQL Copy command by using help from the following StackOverflow post:

Java library to write binary format for Postgres COPY?

I have a Postgres table column character varying(1) which can be null. Basically, this is 1 character field which can be null. so, how can I convert null into a binary string? I used the following way to convert but null is 4-character long. It is working fine with CSV file format but it's not working with a BINARY file format. Any idea will be appreciated.

String nullStr = "null";
strBytes = nullStr.getBytes("UTF-8");
4
  • null is not the same as "null", i.e. the second one is an actual string. Commented Aug 2, 2018 at 1:03
  • Don't go that way. Use the text format. Do you think it is much faster if you convert the data to binary format in your Java code than it is for the PostgreSQL server to do so in C? Also don't forget that the binary format depends on the architecture of the server... Commented Aug 2, 2018 at 8:23
  • yeah, use text or CSV format. Commented Aug 2, 2018 at 8:59
  • thanks all. actually, I am currently using text format. I want to check the performance of binary format. I am just using Java to create the file but this file will be used in postgres. Commented Aug 2, 2018 at 15:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.