Which HSQLDB Data Type is Optimal for 5000 Character String: NTEXT, CLOB or Other.? - hsqldb

I need to store messages of length between 1 and 4200 characters in my database.
Should I create the column with "...NAMEHERE CLOB(5000) NOT NULL, ..." or "...NAMEHERE NTEXT NOT NULL", or is something else optimal?

It works with both VARCHAR(5000) and CLOB(5000). Performance depends on the type of database and table. If your database is all in-memory mem:, use VARCHAR(5000). For file:databases CLOB(5000) uses less memory and should perform better in a large database.
The difference is in the file where the data for this column is stored. With VARCHAR(5000) it is stored together with other columns. With CLOB(5000) it is stored in the separate .lobs file.
If you use CLOB, change the LOB SCALE with SET FILES LOB SCALE 2 to allocate the file spaces in units of 2 kilobytes and reduce waste.

Related

BigQuery storage costs relative to schema?

If I have a column with "numbers" in it, does the storage cost change if the schema specifies that column to be an INTEGER vs STRING?
Example: I have dozens of terabytes of numeric data stored as STRING. If I need to perform math on that column, it's easy enough to cast at query time. But if I change the schema, will the data be stored any differently such that it'll consume less bits at rest, and thus, cost me less?
Given that BigQuery charge STRING/INT64 column as
STRING | 2 bytes + the UTF-8 encoded string size
INT64 | 8 bytes
Not sure how are you planning to encode your numeric data into string, from my gut feeling, unless you have most of the numeric value less than 16 bit, you don't gain much by storing them as STRING than as INT64.
But if you do have small numbers, it is not only saving the cost on storage, but also saving the cost on query if you pay by scanned bytes, which may be more saving than on storage if you scan your data a lot.
Reference: https://cloud.google.com/bigquery/pricing#data

DB2/400 SQL : "ALLOCATE" instruction

A DB2 / 400 SQL question: In the statement below, when creating a column with the "ALLOCATE"
statement, does this mean that the database engine creates the column with an initial size of 20 Mega?
Because the analysis of the system table indicates that the column with a column of 2G, 7M.
Does the size indicated in the "LENGHT" column correspond to the size allocated, or to the maximum size of the column ?
Db2 for IBM i stores table data in two parts.
The Fixed length row-buffer table space and an overflow space.
If a table just has fixed length columns, all the data is in the table space.
ALLOCATE(x) means that the Db allocates x bytes in the table space for the column and the rest is stored in the overflow space.
The default for varying types is allocate(0), so theoretically the entire varying value is store in the overflow space.
Reality is varchar(30) or smaller is stored in the fixed length table space for performance, unless you explicitly specify allocate(0).
The reason it matters, if a query access both the fixed length table space and the overflow space, then 2 I/Os are required to retrieve all the data.
IBM recommends using an allocate(x) where x is large enough to handle at least 80% of values you have.
As you can see for yourself, length is the maximum size for the column.
IBM ACS's schema tool, for one example, shows you the allocated length...
create table mytable (
mykey integer
, myclob clob(200000) allocate(2000)
);

Can i store more than 8000 character in a field of SQL table?

Facing a challenge to store more than 8000 character, but don't wanted to use nvarChar(max) because it will impact on performance.
Is there any way to store character up-to 15000 character in a field without using nvarChar(max)?
And is there any possibility to get increase size of a field dynamically according to data size without use of nvarChar?
Kind of yes, but this gets messy rapidly, and in fact the work around would be worse performance than the varchar(max) option. The issue is the limit of 8060 bytes is permitted on-page for a single row. You can exceed that limit but as long as you accept the data being stored off-page and on a page elsewhere.
Preferred Option : use Varchar(Max) and allow LOB storage to be used.
Alternative : Use multiple varchar(8000) fields, and split / concatenate your string - the data will get Short Large Object'ed (SLOB) and the varchar(8000) fields will be stored off in different pages. This will make it less performant - not to mention the split / concatenate performance issues.
2nd Alternative - compress the data, but there is no guarentee you can still store it within the 8k limit.
Deprecated : Text - do not use this as a solution
In short - do not try to avoid varchar(max) - you would make your life a lot worse.

How to execute query longer than 32767 characters on Firebird?

I'm developing a Java web application that deals with large amounts of text (HTML code strings encoded using base64), which I need to save in my database. I'm using Firebird 2.0, and every time I try to insert a new record with strings longer than 32767 characters, I receive the following error:
GDS Exception. 335544726. Error reading data from the connection.
I have done some research about it, and apparently this is the character limit for Firebird, both for query strings and records in the database. I have tried a couple of things, like splitting the string in the query and then concatenating the parts, but it didn't work. Does anyone know any workarounds for this issue?
If you need to save large amount of text data in the database - just use BLOB fields. Varchar field size is limited to 32Kb.
For better performance you can use binary BLOBs and save there zipped data.
Firebird query strings are limited to 64 kilobytes in Firebird 2.5 and earlier. The maximum length of a varchar field is 32766 byte (which means it can only store 8191 characters when using UTF-8!). The maximum size of a row (with blobs counting for 8 bytes) is 64 kilobytes as well.
If you want to store values longer than 32 kilobytes, you need to use a BLOB SUB_TYPE TEXT, and you need to use a prepared statement to set the value.

Is there a way around the 8k row length limit in SQL Server?

First off, I know that in general having large numbers of wide columns is a bad idea, but this is the format I'm constrained to.
I have an application that imports CSV files into a staging table before manipulating them and inserting/updating values in the database. The staging table is created on the fly and has a variable number of NVARCHAR colums into which the file is imported, plus two INT columns used as row IDs.
One particular file I have to import is about 450 columns wide. With the 24 byte pointer used in a large NVARCHAR column, this adds up to around 10k by my calculations, and I get the error Cannot create a row of size 11166 which is greater than the allowable maximum row size of 8060.
Is there a way around this or are my only choices modifying the importer to split the import or removing columns from the file?
You can use text/ntext which uses 16 bytes pointer. Whereas varchar/nvarchar uses 24bytes pointer.
NVARCHAR(max) or NTEXT can store the data more than 8kb but a record size can not be greater than 8kb till SQL Server 2012. If Data is not fitted in 8kb page size then the data of larger column is moved to another page and a 24 bytes(if data type is varchar/nvarchar) pointer is used to store as reference pointer in main column. if it is text/ntext data type then 16 bytes poiner is used.
For Details you can Visit at following links :
Work around SQL Server maximum columns limit 1024 and 8kb record size
or
http://msdn.microsoft.com/en-us/library/ms186939(v=sql.90).aspx
If you are using SQL Server 2005, 2008 or 2012, you should be able to use NVARCHAR(max) or NTEXT which would be larger than 8,000 characters. MAX will give you 2^31 - 1 characters:
http://msdn.microsoft.com/en-us/library/ms186939(v=sql.90).aspx
I agree that Varchar or nvarchar (Max) is a good solution and will probably work for you, but completeness I will suggest that you can also create more than one table with the two tables having a One-to-One relationship.