Re: Using file data as argument to functions called from psql command line

From: Thom Brown <thombrown(at)gmail(dot)com>
To: Mazen Abdel-Rahman <saba(dot)mazen(at)gmail(dot)com>
Cc: pgsql-novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Using file data as argument to functions called from psql command line
Date: 2009-11-19 10:44:14
Message-ID: bddc86150911190244n306727e9o6f8c281ae10ec9da@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

2009/11/19 Mazen Abdel-Rahman <saba(dot)mazen(at)gmail(dot)com>:
> Hi All,
> Is it possible possible to use a file's data as an argument to one of
> PostgreSQL's functions via the psql command line?
> For example - I know I can do this:
> select xpath('/bookstore/book','<?xml version="1.0"
> encoding="ISO-8859-1"?><bookstore><book><title lang="eng">Harry
> Potter</title><price>29.99</price></book></bookstore>')
>
> Is it possible to read a file to be the second argument in this function?
> (For example books.xml).
> Thank You!
> Mazen Abdel-Rahman

You can write a wrapper function around xpath in pl/perlu (untrusted
pl/perl - http://www.postgresql.org/docs/8.4/static/plperl-trusted.html)
and use file-access commands to read in the file then pass to the
xpath function. However, this introduces security implications, hence
the untrusted name. It is not recommended to use file-system access
directly within queries or functions. If possible, use the COPY
command to import files into tables first.
(http://www.postgresql.org/docs/8.4/static/sql-copy.html)

Regards

Thom

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Ken MacDonald 2009-11-19 16:55:49 Noob question: how to auto-increment index field on INSERT?
Previous Message Mazen Abdel-Rahman 2009-11-19 04:14:42 Using file data as argument to functions called from psql command line