Re: Function with COPY command?

From: "Shoaib Mir" <shoaibmir(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Warren <warren(at)clarksnutrition(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Function with COPY command?
Date: 2007-06-14 20:06:43
Message-ID: bf54be870706141306g3b739f47l374f7e8d53f56da2@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Something like this will help:

CREATE OR REPLACE FUNCTION import_text_file(char(255)) RETURNS void AS $$
DECLARE
filename ALIAS FOR $1;
fin varchar;
BEGIN
fin := 'COPY table from ' || filename;
execute fin;
END;
$$ LANGUAGE plpgsql;

--
Shoaib Mir
EnterpriseDB (www.enterprisedb.com)

On 6/14/07, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> Warren <warren(at)clarksnutrition(dot)com> writes:
> > Is there any way to make this function work?
>
> > CREATE OR REPLACE FUNCTION import_text_file(char(255)) RETURNS void AS
> $$
> > DECLARE
> > filename ALIAS FOR $1;
> > BEGIN
> > COPY table FROM filename;
> > END;
> > $$ LANGUAGE plpgsql;
>
> Use EXECUTE.
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Mason Hale 2007-06-14 20:15:03 Hash Aggregate plan picked for very large table == out of memory
Previous Message Scott Marlowe 2007-06-14 20:02:08 Re: COPY Command and a non superuser user?