pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: John R Pierce <pierce@hogranch.com>
To: pgsql-general@postgresql.org
Subject: Re: which function should i invoke to create a table and insert tuples?
Date: Mon, 17 May 2010 16:38:57 -0700
Message-ID: <4BF1D391.7000109@hogranch.com> (raw)
In-Reply-To: <AANLkTimASu3Z2HZoMfEernYWW-Yf5DXanoxCgaLj-YGV@mail.gmail.com>
References: <AANLkTik3M_WUyPgQe9wMi2v23Hmd9N2p5-ewGV5mSorM@mail.gmail.com>
	<4BF1C0EA.3080008@burntmail.com>
	<AANLkTimASu3Z2HZoMfEernYWW-Yf5DXanoxCgaLj-YGV@mail.gmail.com>

sunpeng wrote:
> it's in source codes,actually i'm writting codes in postgresql source 
> codes,just to verify some of my ideas. C language is used.

you would pass the SQL statements to do what you want to the various 
libpq library functions...


something like...

    PGconn *conn;
    PGresult *res;

    conn = PQconnectdb("dbname=mydatabase");
    if (PQstatus(conn) != CONNECTION_OK) {
    fprintf(stderr, "Connection to database failed: %s",
    PQerrorMessage(conn));
    exit_nicely(conn);
    }

    res = PQexec(conn, "create table test (id serial, num int, value
    text);");
    if (PQresultStatus(res) != PGRES_COMMAND_OK) {
    fprintf(stderr, "BEGIN command failed: %s", PQerrorMessage(conn));
    PQclear(res);
    exit_nicely(conn);
    }
        ...



most folks would probably put the PQexec() and status tests into a 
function to simplify things.




view thread (6+ messages)

Message-ID: <4BF1D391.7000109@hogranch.com>
Permalink:  ../4BF1D391.7000109@hogranch.com/
Also on:    postgresql.org/message-id/4BF1D391.7000109@hogranch.com

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: pierce@hogranch.com
  Subject: Re: which function should i invoke to create a table and insert tuples?
  In-Reply-To: <4BF1D391.7000109@hogranch.com>
  References: <AANLkTik3M_WUyPgQe9wMi2v23Hmd9N2p5-ewGV5mSorM@mail.gmail.com> <4BF1C0EA.3080008@burntmail.com> <AANLkTimASu3Z2HZoMfEernYWW-Yf5DXanoxCgaLj-YGV@mail.gmail.com> <4BF1D391.7000109@hogranch.com>

* 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