How do I store large strings in SQL? I am working ...
# ktor
c
How do I store large strings in SQL? I am working with H2 database in Exposed
google 2
stackoverflow 2
@Matteo Mirk @kenkyee There are so many options available varchar(), blob, varcharN, clob etc. I am getting confused which to use, that's why I asked here. Apologies for not putting it up in the main comment. I don't remember much of SQL from school... I want to store max 10 kb string (inline with the database if possible, not on a separate file system).
And I want to keep the space allocation to a variable to a minimum.
m
This isn’t a Kotlin related question at all and this isn’t the right channel, at least use #random. Anyway this would be more suited for Stack Overflow, but your confusion of varchar and blob in the first place is a sign that you should go back and re-read carefully the documentation for SQL and H2: varchar is a character type, blob is a binary type.
☝️ 1
And I want to keep the space allocation to a variable to a minimum.
Welcome to architectural design tradeoffs 😉 To achieve this you should analyze what kind of data you’ll be storing in that column and try to forecast the maximum length expected. Mysql has the TEXT type for very large strings, I don’t know if H2 does.
c
I am using Ktor with Exposed framework, so I thought this would be the right channel to ask. And Exposed doesn't have the clob datatype which is recommended by H2 doc. So, I was confused about what to use.
currently I am using varchar("name", 10240) , if that doesnt work. I will try out TEXT
thanks for the help
m
No worries. It doesn’t matter if you’re using Ktor and Exposed: please understand that your question is entirely about SQL data definition, there’s nothing Kotlin-specific in your problem. Try finding a SQL type that works for your use case, otherwise you would be better searching on SO.
☝️ 1
106 Views