Re: How to convert ByteA to Large Objects - Mailing list pgsql-general

From Sam Mason
Subject Re: How to convert ByteA to Large Objects
Date
Msg-id 20090123145801.GK3008@frubble.xen.chris-lamb.co.uk
Whole thread Raw
In response to How to convert ByteA to Large Objects  (Howard Cole <howardnews@selestial.com>)
Responses Re: How to convert ByteA to Large Objects  (loamy <broadcast.account@gmail.com>)
List pgsql-general
On Fri, Jan 23, 2009 at 12:08:02PM +0000, Howard Cole wrote:
> Is there some nice SQL I can use to convert a BYTEA field into large
> objects?

You may be able to do something like:

  SELECT oid, lowrite(lo_open(oid, 131072), (SELECT byteafield FROM tbl WHERE x)
  FROM lo_create(NULL) o(oid);

You could turn this around to maybe do:

  UPDATE tbl t SET newoid = (
    SELECT oid FROM (
      SELECT oid, lowrite(lo_open(oid, 131072), t.byteafield)
      FROM lo_create(0) o(oid)) x);

--
  Sam  http://samason.me.uk/

pgsql-general by date:

Previous
From: Sam Mason
Date:
Subject: Re: Using null or not null in function arguments
Next
From: Igor Katson
Date:
Subject: Re: Using null or not null in function arguments