Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I need to store questions and answers in a database. The questions will be one to two sentences, but the answers will be long, at least a paragraph, likely more.

The only way I know about to do this right now is an SQL database. However, I don't feel like this is a good solution because as far as I've seen, these databases aren't used for data of this type or size. Is this the correct way to go or is there a better way to store this data? Is there a better way than storing raw strings?

share|improve this question
    
Have you looked into Full-text search? en.wikipedia.org/wiki/Full_text_search –  FrustratedWithFormsDesigner Mar 23 '12 at 1:24
    
Please define "long" 1k, 5M, 1GB ?? –  James Anderson Mar 23 '12 at 1:30
    
why don't you like "raw" strings? Is the data in fact strings, or is it structured data? Do you plan to do something with it that wouldn't work for strings? There isn't any clear reason in your question why a database wouldn't be appropriate. The same with strings (or perhaps CLOBS if they are too big and depending on what database you use). –  psr Mar 23 '12 at 1:35
    
I was referring to some clever way of storing them, maybe through some type of compression, not plaintext strings. I'm worried about essentially the size of the database here. –  gsingh2011 Mar 23 '12 at 1:46
1  
Which RDBMS are you using? Oracle has some excellent support for handling and searching for text. –  Matthew Flynn Mar 23 '12 at 3:49
show 1 more comment

3 Answers

up vote 4 down vote accepted

Mongodb is great, but you know SQL. There is nothing wrong with storing long answers in fields. You can store images or even files in SQL. I think the max field size is 2gb.

I'm almost positive this answer itself is being stored in table field somewhere.

As for there being thousands of them, no problem. Even millions shouldnt be an issue. You might consider utilizing full text indexing if your searching the field for keywords or something. But, I try not to optimize till I see a problem. Computers are cheap, storage is basically free.

share|improve this answer
1  
+1 on not optimizing until you actually have the problem! –  GrandmasterB Mar 23 '12 at 3:58
    
The max field size is not specified in ANSI SQL, it depends on the DBMS (and usually a few other factors, such as charset, column data type, storage engine, OS, etc.). –  tdammers Mar 23 '12 at 6:42
add comment

There is no problem storing long text in databases (SQL or otherwise). Thats how virtually every blog entry (think Wordpress), news article, and forum post (think phpbb) on the internet is stored. I dont know the specifics of stack exchange's setup, but I'm sure your question is stored in a database, too. Most SQL databases have a TEXT field type or the equivalent just for the purpose of storing textual data of any length. Many also have full text searching systems in place.

Make technical decisions based on technical knowledge and understanding, not feelings.

share|improve this answer
add comment

Yes it's the correct way to go. Storing strings in a SQL database is what you want to do. One of my tables in the DB has over a gig of plaintext data and it performs fine.

If you're worried about storage space - remember that it's cheap!

If you're worried about performance - then don't worry, a good database can scale up (or out) to however much data you want to throw in it.

The last thing you want to do is start optimising now for the sake of it (compressing strings before you put them into the DB or something nuts) before it actually becomes a problem. You're just giving yourself more work.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.