pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mihnea Balta <dark@dark.vodanet.ro>
To: pgsql-interfaces@postgresql.org
Subject: Re: Getting "copy from" to work from a C++ program
Date: Thu, 4 Apr 2002 18:10:26 +0300
Message-ID: <20020404150413.0EEB04763B6@postgresql.org> (raw)
In-Reply-To: <3CABD1C3.8020606@mo.com>
References: <3CABD1C3.8020606@mo.com>

On Thursday 04 April 2002 07:08, you wrote:
> Hi,
>
> I'm trying to insert several records into a table in one shot
> (from a C++ program, that is).
>
> All my attempts to use "copy from" have failed  (well, I
> haven't tried copying from an actual file, since I have
> the data in memory, and I'd like to avoid the overhead
> to write it to a file first).  Is it possible??  I've
> tried things like:
>
> PgDatabase db(" ..... ");
> db.Exec ("copy deleteme from stdin\n1\tName1\n2\tName2");

I use this (libpq, not libpq++, but you'll get it):

void dbcon::copy(char* table, char* buf){
        char copy_qry[256];

        snprintf(copy_qry, 256, "copy %s from stdin", table);
        PQexec(conn, copy_qry);
        PQputline(conn, buf);
        PQputline(conn, "\\.\n");
        PQendcopy(conn);
}




view thread (2+ messages)

Message-ID: <20020404150413.0EEB04763B6@postgresql.org>
Permalink:  ../20020404150413.0EEB04763B6@postgresql.org/
Also on:    postgresql.org/message-id/20020404150413.0EEB04763B6@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: dark@dark.vodanet.ro
  Subject: Re: Getting "copy from" to work from a C++ program
  In-Reply-To: <20020404150413.0EEB04763B6@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox