Re: How to get text for a plpgsql variable from a file.

From: Erik Jones <ejones(at)engineyard(dot)com>
To: Erwin Brandstetter <brsaweda(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to get text for a plpgsql variable from a file.
Date: 2009-12-17 09:48:23
Message-ID: 1C91B879-F8C7-4789-BEEB-6BC43FF156A5@engineyard.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Dec 16, 2009, at 11:19 AM, Erwin Brandstetter wrote:

> Hello,
>
> I need a long text form from a file in my plpgsql variable.
> Can anyone think of a more straightforward way to read the file than
> the following:
>
>
> CREATE FUNCTION test() RETURNS void AS
> $BODY$
> DECLARE
> mytxt text;
> BEGIN
>
> CREATE TEMP TABLE x (x text);
> COPY x from '/path/to/myfile.txt';
> mytxt := (SELECT x from x);
>
> ...
>
> END;
> $BODY$
> LANGUAGE 'plpgsql' VOLATILE;

If you're allowed, you can use an untrusted procedural language.

Erik Jones, Database Administrator
Engine Yard
Support, Scalability, Reliability
866.518.9273 x 260
Location: US/Pacific
IRC: mage2k

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ivan Sergio Borgonovo 2009-12-17 10:58:06 Re: flagging first row inserted for each "group" of key
Previous Message Erik Jones 2009-12-17 09:41:54 Re: Justifying a PG over MySQL approach to a project