Re: BYTEA vs BLOB

From: Andreas Joseph Krogh <andreas(at)visena(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: BYTEA vs BLOB
Date: 2016-01-17 15:01:03
Message-ID: VisenaEmail.a0.92ae40c7c924b9ef.15250188270@tc7-visena
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-sql

På lørdag 16. januar 2016 kl. 17:08:05, skrev Eugene Yin <eugeneymail(at)ymail(dot)com
<mailto:eugeneymail(at)ymail(dot)com>>:
When use Ora2Pg to migrate the Oracle to Pg, the BLOB data type in Oracle will
supposedly be converted into BYTEA in Pg.  Is this achievable?  
 
If so, after the data become BYTEA, can I further convert the BYTEA into OID
data type, and how to?

 
Here's how I converted a BYTEA-column to OID:
 
The table origo_file_rawdata contains a column named 'data' of type BYTEA. The
trick is to add a new column, 'lo_data' of type=OID, populate it, then drop the
old column and rename 'lo_data' to 'data':
begin; alter table origo_file_rawdata add column lo_data oid; do $$ declare
loid oid; lfd integer; lsize integer; d origo_file_rawdata; begin for d IN
(select * from origo_file_rawdata) loop loid := lo_create(0); lfd :=
lo_open(loid,131072); lsize := lowrite(lfd, d.data); perform lo_close(lfd);
update origo_file_rawdata set lo_data = loid where entity_id = d.entity_id; end
loop;end; $$; alter table origo_file_rawdata alter column lo_data set not null;
alter tableorigo_file_rawdata drop column data; alter table origo_file_rawdata
renamelo_data to data; commit;  

Hope this helps.
 
-- Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
andreas(at)visena(dot)com <mailto:andreas(at)visena(dot)com>
www.visena.com <https://www.visena.com>
<https://www.visena.com>

 

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Eugene Yin 2016-01-17 16:28:28 tablespace
Previous Message Eugene Yin 2016-01-16 16:08:05 Re: BYTEA vs BLOB