agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Andreas Joseph Krogh <andreas@visena.com>
To: pgsql-sql@postgresql.org
Subject: Re: BYTEA vs BLOB
Date: Sun, 17 Jan 2016 16:01:03 +0100 (CET)
Message-ID: <VisenaEmail.a0.92ae40c7c924b9ef.15250188270@tc7-visena> (raw)
In-Reply-To: <563742622.6654475.1452960485450.JavaMail.yahoo@mail.yahoo.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>

På lørdag 16. januar 2016 kl. 17:08:05, skrev Eugene Yin <eugeneymail@ymail.com 
<mailto: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 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@visena.com <mailto:andreas@visena.com>
www.visena.com <https://www.visena.com;
 <https://www.visena.com;


 

view thread (8+ messages)  latest in thread

Message-ID: <VisenaEmail.a0.92ae40c7c924b9ef.15250188270@tc7-visena>
Permalink:  ../VisenaEmail.a0.92ae40c7c924b9ef.15250188270@tc7-visena/
Also on:    postgresql.org/message-id/VisenaEmail.a0.92ae40c7c924b9ef.15250188270@tc7-visena

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: andreas@visena.com
  Subject: Re: BYTEA vs BLOB
  In-Reply-To: <VisenaEmail.a0.92ae40c7c924b9ef.15250188270@tc7-visena>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox