Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force Liquibase to map Blob to BYTEA on PostgreSQL

How to tell Liquibase to map BLOB datatype to BYTEA on PostgreSQL?

It seems that Hibernate people has taken over and adapted the tool to their needs: https://liquibase.jira.com/browse/CORE-1863 , however, EclipseLink don't support oid's and the bug seems to be still open: https://bugs.eclipse.org/bugs/show_bug.cgi?id=337467

I need to use EclipseLink, and I need to use blobs with PostgreSQL. I'd like to use Liquibase, is it possible to make those things work together?

like image 929
Danubian Sailor Avatar asked Feb 22 '17 10:02

Danubian Sailor


People also ask

How do I declare a blob in PostgreSQL?

The storage size of blob data type in PostgreSQL is 1 to 4 bytes plus the string of actual binary, input format of blob data type is different in PostgreSQL. Below is the syntax : Create table name_of_table (name_of_column1 data_type, name_of_column2 data_type, name_of_column3 data_type, …, name_of_columnN bytea);

What is Bytea in PostgreSQL?

The bytea data type allows the storage of binary strings or what is typically thought of as “raw bytes”. Materialize supports both the typical formats for input and output: the hex format and the historical PostgreSQL escape format. The hex format is preferred.


1 Answers

You have two options.

If you only need this for Postgres and don't plan to support other DBMS, simply use bytea as the column type.

Any data type that is not listed as one of the "generic" types in the description of the column tag will be passed "as-is" to the database, e.g.

<createTable tableName="foo">
  <column name="id" type="integer"/> 
  <column name="picture" type="bytea"/>
</createTable>

If you want to support different DBMS, you can define a property depending on the DBMS:

<property name="blob_type" value="bytea" dbms="postgresql"/>
<property name="blob_type" value="blob" dbms="oracle"/>

then later

<createTable tableName="foo">
  <column name="id" type="integer"/> 
  <column name="picture" type="${blob_type}"/>
</createTable>
like image 177
a_horse_with_no_name Avatar answered Sep 21 '22 19:09

a_horse_with_no_name