Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id BEC40633798 for ; Mon, 17 May 2010 20:39:19 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 98420-01 for ; Mon, 17 May 2010 23:39:11 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from hogranch.com (hogranch.com [75.101.82.47]) by mail.postgresql.org (Postfix) with ESMTP id 85F456336DF for ; Mon, 17 May 2010 20:39:12 -0300 (ADT) Received: from [192.168.0.2] (porker [192.168.0.2]) by hogranch.com (8.11.6/8.11.6) with ESMTP id o4HNd2L26781 for ; Mon, 17 May 2010 16:39:02 -0700 Message-ID: <4BF1D391.7000109@hogranch.com> Date: Mon, 17 May 2010 16:38:57 -0700 From: John R Pierce User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) MIME-Version: 1.0 To: pgsql-general@postgresql.org Subject: Re: which function should i invoke to create a table and insert tuples? References: <4BF1C0EA.3080008@burntmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-HawgScanner-Information: Please contact the ISP for more information X-HawgScanner: Found to be clean X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201005/674 X-Sequence-Number: 163043 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.