computing and updating the size of a table with large objects - Mailing list pgsql-general

From Marco Bizzarri
Subject computing and updating the size of a table with large objects
Date
Msg-id 3f0d61c40708310954h7fcfdf4ajed2637abb9f8817@mail.gmail.com
Whole thread Raw
Responses Re: computing and updating the size of a table with large objects
Re: computing and updating the size of a table with large objects
List pgsql-general
Hi all.

I've a table with large objects, here is the definition:


PAFlow-emmebi=# \d documenti
           Tabella "public.documenti"
 Colonna |         Tipo          | Modificatori
---------+-----------------------+--------------
 id_doc  | character varying(50) | not null
 file    | oid                   |
 kind    | integer               | not null
 size    | bigint                |
Indici:
    "documenti_pkey" chiave primaria, btree (id_doc, kind)

(sorry for the mixed language output)

I need to populate the size attribute with the size of the large object in file.

My first attempt was:

SELECT  lo_lseek(lo_open(file, 262144), 0, 2) AS size FROM documenti ;

This opens the largeobject, and passes the result to the lo_lseek,
which goes up to the end of the largeobject, and thus computes the
size.

Now I could prepare an update which does the job. My doubt is that I
could use all the resources in the update (documenti table is quite
large).

I thought I could use something like this:

SELECT  lo_lseek(lo_open(file, 262144), 0, 2) AS size, lo_close(0)
FROM documenti ;

which is quite nasty, and relies on side effects happening in the
proper order, but uses just one file descriptor for all the query.

Does anyone has any other suggestion?

Regards
Marco

--
Marco Bizzarri
http://iliveinpisa.blogspot.com/

pgsql-general by date:

Previous
From: Erik Jones
Date:
Subject: Re: Obtaining random rows from a result set
Next
From: Jeff Davis
Date:
Subject: Re: auditing in postgresql