Discussion:
Get file size
(too old to reply)
Lukas
2012-09-04 19:09:42 UTC
Permalink
Hello,

maybe someone can give an idea how I cat get sizes of file which location
is know?
Lets say I have table with 200k records, in every record one column
indicates full file path on server for ex. "c:\temp\test.txt" etc. and I
want to fill that table with file sizes..
I was looking for function in plpgsql or plpgper languages, but I did not
found anything what could help me..

Lukas
--
Sent via pgsql-novice mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice
Alan Hodgson
2012-09-04 19:51:42 UTC
Permalink
Post by Lukas
Hello,
maybe someone can give an idea how I cat get sizes of file which location
is know?
Lets say I have table with 200k records, in every record one column
indicates full file path on server for ex. "c:\temp\test.txt" etc. and I
want to fill that table with file sizes..
I was looking for function in plpgsql or plpgper languages, but I did not
found anything what could help me..
This wouldn't be a good use for a database function.

Write it in your favourite client language and connect to the database from
there, where it can run with permissions appropriate to whatever file system
it's reading.
--
Sent via pgsql-novice mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice
Josh Kupershmidt
2012-09-04 21:37:56 UTC
Permalink
Post by Lukas
maybe someone can give an idea how I cat get sizes of file which location
is know?
Lets say I have table with 200k records, in every record one column
indicates full file path on server for ex. "c:\temp\test.txt" etc. and I
want to fill that table with file sizes..
I was looking for function in plpgsql or plpgper languages, but I did not
found anything what could help me..
If the files you need to read are located within your PGDATA
directory, you could get away with using pg_stat_file(). Otherwise, I
think you'll need to create a quick function in PL/Python, PL/Perl, or
similar. Example:

CREATE OR REPLACE FUNCTION file_size (v_fname text)
RETURNS bigint
AS $$
import os
size = None
try:
size = os.path.getsize(v_fname)
except os.error, exc:
pass
return size
$$ LANGUAGE plpythonu VOLATILE STRICT;

Josh
--
Sent via pgsql-novice mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice
Loading...