Re: BYTEA vs BLOB - Mailing list pgsql-sql

From Andreas Joseph Krogh
Subject Re: BYTEA vs BLOB
Date
Msg-id VisenaEmail.a0.92ae40c7c924b9ef.15250188270@tc7-visena
Whole thread Raw
In response to Re: BYTEA vs BLOB  (Eugene Yin <eugeneymail@ymail.com>)
Responses Re: BYTEA vs BLOB
List pgsql-sql
På lørdag 16. januar 2016 kl. 17:08:05, skrev Eugene Yin <eugeneymail@ymail.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 table origo_file_rawdata drop column data;
alter table origo_file_rawdata rename lo_data to data;
commit;
 
Hope this helps.
 
--
Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
 
Attachment

pgsql-sql by date:

Previous
From: Eugene Yin
Date:
Subject: Re: BYTEA vs BLOB
Next
From: Eugene Yin
Date:
Subject: tablespace