From: | Bill Todd <pg(at)dbginc(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: How use input parameter as path to COPY in function? |
Date: | 2009-11-26 19:02:27 |
Message-ID: | 4B0ED0C3.20400@dbginc.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Thanks Tom. As usual, I learned a lot more from your reply than just the
answer to my question .
Bill
Tom Lane wrote:
> Bill Todd <pg(at)dbginc(dot)com> writes:
>
>> I am missing something basic. How can I use an input parameter as the
>> destination path in a COPY statement in a function.
>>
>
> plpgsql can only substitute parameter values into places where a data
> value is called for in a DML statement (ie, SELECT/INSERT/UPDATE/DELETE).
> To use a parameter in other contexts, such as a utility statement like
> COPY, you need to construct the command as a string and EXECUTE it.
> Try something like
>
> EXECUTE 'copy dvd.genre to ' || quote_literal(export_path) ||
> $q$
> with
> delimiter as E'\t'
> null as ''
> $q$ ;
>
> (There's any number of ways to do the quoting here, of course,
> but I do strongly recommend using quote_literal() on the parameter.)
>
> regards, tom lane
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Thomas Kellerer | 2009-11-26 21:59:05 | date_trunct() and start of week |
Previous Message | Scott Marlowe | 2009-11-26 16:57:45 | Re: READ ONLY & I/O ERROR |