Re: which function should i invoke to create a table and insert tuples?

From: John R Pierce <pierce(at)hogranch(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: which function should i invoke to create a table and insert tuples?
Date: 2010-05-17 23:38:57
Message-ID: 4BF1D391.7000109@hogranch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message John R Pierce 2010-05-18 02:56:04 [Fwd: failure notice]
Previous Message sunpeng 2010-05-17 23:17:36 Re: which function should i invoke to create a table and insert tuples?