What is the standard SQL type for binary data? - sql

I have a function which maps java to SQL types.
As I want to store binary data, is there any type defined by the SQL standard which I can use both in PostgreSQL and hsqldb?

The SQL 92 standard does not define a binary type. PostgreSQL has a bytea type, hsqldb has a binary type.
For a very portable (if not efficient) solution, convert the binary to base64, and store it in a string.

BINARY and VARBINARY are defined by the the SQL Standard. The Standard is currently at SQL:2011 (after 92, 1999, 2003 and 2008). HSQLDB supports all the core data types defined by the Standard.
The PostgreSQL BYTEA is similar to VARBINARY. You can define the BYTEA type in HSQLDB as a VARBINARY type with a large maximum size:
CREATE TYPE BYTEA AS VARBINARY(1000000)

SQL has supported binary types since 1999: [https://mariadb.com/kb/en/sql-data-types/]. Vendors have had over a decade to add support for binary types, and most SQL databases do.

Related

How to query BLOB as CLOB in H2 database

To project BLOB into CLOB in Oracle I can do this query:
SELECT ent.ID, to_clob(ent.blob_string) from entity_1 ent;
However, I could not find the to_clob equivalent operation in H2 to see my data in H2-console. How I can do that?
It depends on content of your BLOB. In H2 Console you actually can see BLOB and other binary values as is in hexadecimal representation without any additional functions around them.
You can use CAST(ent.blob_string AS VARCHAR) (or CAST(ent.blob_string AS CLOB)) to convert a binary string to a character string explicitly, but such conversion uses different encodings in different versions of H2. Old versions use hexadecimal representation, new versions use UTF-8. You can use UTF8TOSTRING(ent.blob_string) function for UTF-8 conversion in old and new versions. There is also RAWTOHEX(ent.blob_string) function, but its behavior is also different between different versions of H2 and its compatibility modes.

SQL cast target types: standardized?

SQL function
cast(expression as type):
It is ANSI standard. Is the type standardized? what types are allowed? Are they different from database to database?
Looked at the MySQL and others. MySQL has signed/unsigned, others has INT.
CAST() is ANSI standard. Off the top of my head, ANSI data types are things like:
DECIMAL/NUMERIC(scale, precision)
VARCHAR()/CHAR()
DATE/TIME/DATETIME/INTERVAL
DOUBLE PRECISION/FLOAT
BIGINT/INT/SMALLINT
MySQL changes the syntax a bit. So, UNSIGNED and SIGNED are used instead of INT. And CHAR is used for all the character types. Other databases have their own modification for CAST(). For instance Google BigQuery uses string instead of the character types.

Insert BLOB data into SQLite database field using Matlab and SQL query. Any idea?

I need to store binary data in single database field (DB is SQLite, it's important!). Binary data is a some one-dimensional array.One of the best way to do that is BLOB data insertion. As far as I know Matlab doesn't consist methods for BLOB data processing. How can I do that using Matlab environment? Maybe using raw SQL query?
In a raw SQLite query, a blob can be written as a x-prefixed string, with each byte representeded by a two-digit hexadecimal number:
INSERT INTO MyTable(BlobColumn) VALUES(x'0123AB');
To return a blob as text from a query, you can use the quote() function, which uses the same format:
SELECT quote(BlobColumn) FROM MyTable; --> returns the string "x'0123AB'"
It might be a better idea to use some other SQLite3 driver for Matlab, e.g., https://github.com/kyamagu/matlab-sqlite3-driver, http://jaewon.mine.nu/jaewon/2015/06/17/another-sqlite-interface-for-matlab/.

MLSLABEL Oracle datatype

Where can practically use this type?
What is the MLSLABEL Oracle datatype?
This theme is very old so it can have practical use of this type?
MLSLABEL : The Oracle PL/SQL datatype MLSLABEL is used to store an
operating system label in binary format. It is used for Oracle Label
Security (which was earlier known as Trusted Oracle MLS RDBMS). The
maximum precision for MLSLABEL column is 255 bytes; its Datatype Code
is "105".
http://psoug.org/definition/MLSLABEL.htm

which data type can save bangla Language in sql server?

I want to save bangla Language in sql server. Using which data type I can Do it in sql server 2005 or sql server 2008.
I tried varchar and varbinary type but it cannot save bangla Language.
How is it possible?
You're using SQL_Latin1_General_CP1_CI_AS for your collation, which is suited for the Latin character set (ISO-8859-1). To store characters fromother character sets, you can use the NVARCHAR() which can store the full Unicode range, irrespective of collation - this does mean it will need to be treated as NVARCHAR() all the way, as quoted constants (e.g. N'বাংলা Bangla'), as the data types for parameters to stored procedures, etc.