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