Re: Copying large object in a stored procedure

From: Csaba Nagy <nagy(at)ecircle-ag(dot)com>
To: Postgres general mailing list <pgsql-general(at)postgresql(dot)org>
Subject: Re: Copying large object in a stored procedure
Date: 2008-04-15 12:19:14
Message-ID: 1208261954.8259.333.camel@PCD12478
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> Is there an easy way to copy a large object to a new one, having a new
> OID and it's content independent from the original ?

So my current solution would be:

CREATE OR REPLACE FUNCTION copy_blob(p_blobId OID)
RETURNS OID AS '
DECLARE
v_NewOID BIGINT;
BEGIN
SELECT lo_create(0) INTO v_NewOID;

DELETE FROM pg_largeobject WHERE loid = v_NewOID;

INSERT INTO pg_largeobject (loid, pageno, data)
SELECT v_NewOID, pageno, data
FROM pg_largeobject
WHERE loid = p_blobId;

RETURN v_NewOID;
END;
' LANGUAGE plpgsql;

I would still be grateful if anybody knows a better solution using plain
SQL/plpgsql...

Cheers,
Csaba.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Csaba Nagy 2008-04-15 12:26:28 Re: Copying large object in a stored procedure
Previous Message Karsten Hilbert 2008-04-15 11:50:49 Re: Storage sizes for dates/times (documentation bug?)