Re: BYTEA vs BLOB - Mailing list pgsql-sql

From Eugene Yin
Subject Re: BYTEA vs BLOB
Date
Msg-id 1487961919.5778438.1453049793112.JavaMail.yahoo@mail.yahoo.com
Whole thread Raw
In response to Re: BYTEA vs BLOB  (Andreas Joseph Krogh <andreas@visena.com>)
Responses Re: BYTEA vs BLOB
List pgsql-sql
lfd := lo_open(loid,131072);

Why use the file size 131072, instead of other number?
Are there other options?  I mean, under what circumstance, use 131072, or use other size?

Thanks

Eugene


On Sunday, January 17, 2016 7:02 AM, Andreas Joseph Krogh <andreas@visena.com> wrote:


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: tablespace
Next
From: Andreas Joseph Krogh
Date:
Subject: Re: BYTEA vs BLOB