Arjun Raj
Arjun Raj

Reputation: 984

using pg_read_file read file in desktop PostgreSQL

I wanted to how to read a file in my desk top using pg_read_file in PostgreSQL

pg_read_file(filename text [, offset bigint, length bigint])

my query

select pg_read_file('/root/desktop/new.txt' , 0 , 1000000);

error

ERROR:  absolute path not allowed

UPDATE

Upvotes: 7

Views: 37242

Answers (4)

Wh1t3 P4wn48
Wh1t3 P4wn48

Reputation: 21

To read the content of a file from PostgreSQL you can use this.

CREATE TABLE demo(t text);
COPY demo from '[FILENAME]';
SELECT * FROM demo;

Each text-line in a SQL-ROW. Useful for temporary transfers.

Upvotes: 2

chetan chadha
chetan chadha

Reputation: 1

lo_import(file path) will generate an oid.This may solve your problem. you can import any type of file using this (even image)

Upvotes: 0

Craig Ringer
Craig Ringer

Reputation: 324385

If you're using psql you can use \lo_import to create a large object from a local file.

The pg_read_file tool only allows reads from server-side files.

Upvotes: 8

Houari
Houari

Reputation: 5621

pg_read_file can read the files only from the data directory path, if you would like to know your data directory path use:

SHOW  data_directory;

I think that you can resolve you problem by looking to this post

Upvotes: 12

Related Questions