Force Liquibase to map Blob to BYTEA on PostgreSQL

自作多情 提交于 2021-02-07 13:13:59

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/42388886/force-liquibase-to-map-blob-to-bytea-on-postgresql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!