4

I have incoming xml which is potentially as big as 5M and I need to store it it with postgres 9.1. Which data type should I use ?

bytea 
character varying
text

or something else ?

BTW The xml itself contains some binary data in base64 format, does that make any difference when choosing data type in postgres ?

Thank

6
  • 4
    xml maybe? Definitely not bytea as that is for binary data, varchar and text are effectively the same thing in Postgres (as documented in the manual). Commented May 18, 2013 at 15:36
  • The xml itself contains some binary data encoded in base64 format, does that make any difference? Commented May 18, 2013 at 15:48
  • 2
    XML is text (strings) you cannot have "real" binary data in it. Everything in there is represented as a String. Commented May 18, 2013 at 15:50
  • 1
    base64 encoded data is text. So no difference. Commented May 18, 2013 at 15:51
  • 2
    But the fact the String can be as big as 5M in size would it be storing bytea have certain advantage ? Can xml or char varying cope with 5M long string effectively (load and save)? Commented May 18, 2013 at 16:02

1 Answer 1

6

You have two options:

  1. VARCHAR or TEXT. It will allow you to store and retrieve your XML file from DB. But nothing more.
  2. XML . Will allow you to store, retrieve, validate, edit, search ... the XML files, but may (or may not) involve some overhead on storing files to DB.

There is no reason to store XML files as BYTEA at all. 5 MB size is nothing special for Postgres. In my last project I worked strings with up to 0.5 GB length in Postgres.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your answer and you stored the 0.5G length string with Text or VarChar and works fine?
@Gob00st There were some problems on driver level, when storing 100+ MB varchar to DB. There were no problems with 5-10 MB strings.
Thanks mine is 5 upper limit so should be fine.

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.