Re: [DEFAULT] Daily digest v1.4551 (20 messages) - Mailing list pgsql-general

From Daniel Verite
Subject Re: [DEFAULT] Daily digest v1.4551 (20 messages)
Date
Msg-id 20040729011602.5787736@localhost
Whole thread Raw
In response to Re: [DEFAULT] Daily digest v1.4551 (20 messages)  (Jerry LeVan <jerry.levan@eku.edu>)
List pgsql-general
         Jerry LeVan writes

> Is it the case that "insert" could be used in a similiar
> fashion to load the bytea field?

Here's a code snippet for inserting a (varchar,bytea) tuple.

int write_bytea(const char* pkey, const char* buf, int size)
{
 Oid in_oid[]={1043,17}; /* varchar, bytea */
 const char* params[]={pkey,buf};
 const int params_length[]={strlen(pkey),size};
 const int params_format[]={0,1}; /* text,binary */
 PGresult* res;
 res = PQexecParams(pgconn,  
                    "INSERT INTO tblob(pkey,contents) VALUES ($1,$2)",  
                    sizeof(params)/sizeof(params[0]),
                    in_oid, params, params_length,
                    params_format, 1);
 if (res && PQresultStatus(res)==PGRES_COMMAND_OK) {
  /* success */
 }
}

--
 Daniel
 PostgreSQL-powered mail user agent and storage: http://www.manitou-mail.org


pgsql-general by date:

Previous
From: Steve Crawford
Date:
Subject: Re: Timestamp input + copy
Next
From: Tom Lane
Date:
Subject: Re: Timestamp input + copy