Re: which function should i invoke to create a table and insert tuples? - Mailing list pgsql-general

From John R Pierce
Subject Re: which function should i invoke to create a table and insert tuples?
Date
Msg-id 4BF1D391.7000109@hogranch.com
Whole thread Raw
In response to Re: which function should i invoke to create a table and insert tuples?  (sunpeng <bluevaley@gmail.com>)
List pgsql-general
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.


pgsql-general by date:

Previous
From: sunpeng
Date:
Subject: Re: which function should i invoke to create a table and insert tuples?
Next
From: John R Pierce
Date:
Subject: [Fwd: failure notice]