Re: Passing Parameters to copy_expert()?

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: Victor Hooi <victorhooi(at)yahoo(dot)com>
Cc: "psycopg(at)postgresql(dot)org" <psycopg(at)postgresql(dot)org>
Subject: Re: Passing Parameters to copy_expert()?
Date: 2013-11-08 10:44:39
Message-ID: CA+mi_8aPZX1nXWSD8UyML2csscmm9fK6KpQnBhfLdQ3T=bkAxw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On Fri, Nov 8, 2013 at 8:22 AM, Victor Hooi <victorhooi(at)yahoo(dot)com> wrote:
> Hi,
>
> I'm trying to use the copy_expert() command to dump records from a database
> to CSV.
>
> http://initd.org/psycopg/docs/cursor.html#cursor.copy_expert
>
> However, I need to pass some parameters into the SQL statement - namely the
> values for a WHERE IN clause.
>
> (Basically, the COPY operation is too big for our PostgreSQL server to
> handle, so we're chunking it up into multiple queries - hence, needing to
> pass in values to WHERE IN).
>
> I can't seem to see anything in the docs about this about how to pass
> parameters through to copy.
>
> I could use Python's own string interpolation, however, I'm under the
> impression that's a pretty bad thing.
>
> Is there another way to pass parameters to copy_expert()?

Hello Victor,

unfortunately no, copy doesn't support parameters. It seems an useful feature.

Even if it is meant for debugging purpose you can use
cursor.mogrify(query, args) that would return you the query merged
with the argument and pass such result to copy_expert().

http://initd.org/psycopg/docs/cursor.html#cursor.mogrify

Hope this helps.

-- Daniele

In response to

Browse psycopg by date

  From Date Subject
Next Message Victor Hooi 2013-11-11 07:36:04 Parametised query wraps everything in single quotes?
Previous Message Victor Hooi 2013-11-08 08:22:48 Passing Parameters to copy_expert()?