Re: Copying large object in a stored procedure - Mailing list pgsql-general

From Csaba Nagy
Subject Re: Copying large object in a stored procedure
Date
Msg-id 1208261954.8259.333.camel@PCD12478
Whole thread Raw
In response to Copying large object in a stored procedure  (Csaba Nagy <nagy@ecircle-ag.com>)
Responses Re: Copying large object in a stored procedure  (Csaba Nagy <nagy@ecircle-ag.com>)
List 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.



pgsql-general by date:

Previous
From: Karsten Hilbert
Date:
Subject: Re: Storage sizes for dates/times (documentation bug?)
Next
From: Csaba Nagy
Date:
Subject: Re: Copying large object in a stored procedure