https://kotlinlang.org logo
#ktor
Title
# ktor
c

Cheenu Soni

01/29/2021, 7:37 AM
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

Matteo Mirk

01/30/2021, 7:12 AM
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

Cheenu Soni

01/30/2021, 7:19 AM
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

Matteo Mirk

01/30/2021, 8:36 AM
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
81 Views