pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
which function should i invoke to create a table and insert tuples?
6+ messages / 4 participants
[nested] [flat]

* which function should i invoke to create a table and insert tuples?
@ 2010-05-17 14:31 sunpeng <bluevaley@gmail.com>
  2010-05-17 14:43 ` Re: which function should i invoke to create a table and insert tuples? Thom Brown <thombrown@gmail.com>
  2010-05-17 22:19 ` Re: which function should i invoke to create a table and insert tuples? Guy Rouillier <guyr-ml1@burntmail.com>
  0 siblings, 2 replies; 6+ messages in thread

From: sunpeng @ 2010-05-17 14:31 UTC (permalink / raw)
  To: pgsql-general

hi,when i do experiment on postgresql 8.4,i need to create a table and
insert some tuples,which function should i invoke?
for example,i want to create a table with "create table test (uid
int,catcode int)" and insert tuples with "insert into test values(1,1)".
thanks millions!

peng

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: which function should i invoke to create a table and insert tuples?
  2010-05-17 14:31 which function should i invoke to create a table and insert tuples? sunpeng <bluevaley@gmail.com>
@ 2010-05-17 14:43 ` Thom Brown <thombrown@gmail.com>
  2010-05-17 15:04   ` Re: which function should i invoke to create a table and insert tuples? Thom Brown <thombrown@gmail.com>
  1 sibling, 1 reply; 6+ messages in thread

From: Thom Brown @ 2010-05-17 14:43 UTC (permalink / raw)
  To: sunpeng <bluevaley@gmail.com>; +Cc: pgsql-general

On 17 May 2010 15:31, sunpeng <bluevaley@gmail.com> wrote:

> hi,when i do experiment on postgresql 8.4,i need to create a table and
> insert some tuples,which function should i invoke?
> for example,i want to create a table with "create table test (uid
> int,catcode int)" and insert tuples with "insert into test values(1,1)".
> thanks millions!
>
> peng
>

What is it you're testing?

You can insert many rows into a table by doing something like the following:

CREATE TABLE test
(
test_id serial,
test_num int
test_value int
)

INSERT INTO test (test_num, test_value)
SELECT s.a, ceil(random()*100) FROM generate_series(1,1000) as s(a);

That would just put 1,000 entries into the table, the first column would get
its value from its sequence, the second from the series and the third would
be random.

Regards

Thom

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: which function should i invoke to create a table and insert tuples?
  2010-05-17 14:31 which function should i invoke to create a table and insert tuples? sunpeng <bluevaley@gmail.com>
  2010-05-17 14:43 ` Re: which function should i invoke to create a table and insert tuples? Thom Brown <thombrown@gmail.com>
@ 2010-05-17 15:04   ` Thom Brown <thombrown@gmail.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Thom Brown @ 2010-05-17 15:04 UTC (permalink / raw)
  To: sunpeng <bluevaley@gmail.com>; +Cc: pgsql-general

On 17 May 2010 15:53, sunpeng <bluevaley@gmail.com> wrote:

> Thanks for your quickly reply.
> Maybe i haven't expressed clearly.My purpose is in the postgresql source
> codes which function invoke should i use to create table and insert tuples.
> for example are there any function just like _createTable(char
> *tableName,int firstColumn,int secondColumn) ?
>
>
Please use "reply to all" so everyone can see your responses.

I'm not aware of anything that will do what you're asking.  You can use
client interfaces (
http://www.postgresql.org/docs/8.4/static/client-interfaces.html) but as for
libraries with variadic functions, I wouldn't know.

Regards

Thom

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: which function should i invoke to create a table and insert tuples?
  2010-05-17 14:31 which function should i invoke to create a table and insert tuples? sunpeng <bluevaley@gmail.com>
@ 2010-05-17 22:19 ` Guy Rouillier <guyr-ml1@burntmail.com>
  2010-05-17 23:17   ` Re: which function should i invoke to create a table and insert tuples? sunpeng <bluevaley@gmail.com>
  1 sibling, 1 reply; 6+ messages in thread

From: Guy Rouillier @ 2010-05-17 22:19 UTC (permalink / raw)
  To: pgsql-general

On 5/17/2010 10:31 AM, sunpeng wrote:
> hi,when i do experiment on postgresql 8.4,i need to create a table and
> insert some tuples,which function should i invoke?
> for example,i want to create a table with "create table test (uid
> int,catcode int)" and insert tuples with "insert into test values(1,1)".
> thanks millions!

What do you mean by function?  Are you trying to do this from PgAdmin, 
from a stored proc or from some flavor of source code?  If either of the 
latter two, which language?

-- 
Guy Rouillier



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: which function should i invoke to create a table and insert tuples?
  2010-05-17 14:31 which function should i invoke to create a table and insert tuples? sunpeng <bluevaley@gmail.com>
  2010-05-17 22:19 ` Re: which function should i invoke to create a table and insert tuples? Guy Rouillier <guyr-ml1@burntmail.com>
@ 2010-05-17 23:17   ` sunpeng <bluevaley@gmail.com>
  2010-05-17 23:38     ` Re: which function should i invoke to create a table and insert tuples? John R Pierce <pierce@hogranch.com>
  0 siblings, 1 reply; 6+ messages in thread

From: sunpeng @ 2010-05-17 23:17 UTC (permalink / raw)
  To: Guy Rouillier <guyr-ml1@burntmail.com>; +Cc: pgsql-general

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.

2010/5/17 Guy Rouillier <guyr-ml1@burntmail.com>

> On 5/17/2010 10:31 AM, sunpeng wrote:
>
>> hi,when i do experiment on postgresql 8.4,i need to create a table and
>> insert some tuples,which function should i invoke?
>> for example,i want to create a table with "create table test (uid
>> int,catcode int)" and insert tuples with "insert into test values(1,1)".
>> thanks millions!
>>
>
> What do you mean by function?  Are you trying to do this from PgAdmin, from
> a stored proc or from some flavor of source code?  If either of the latter
> two, which language?
>
> --
> Guy Rouillier
>
> --
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: which function should i invoke to create a table and insert tuples?
  2010-05-17 14:31 which function should i invoke to create a table and insert tuples? sunpeng <bluevaley@gmail.com>
  2010-05-17 22:19 ` Re: which function should i invoke to create a table and insert tuples? Guy Rouillier <guyr-ml1@burntmail.com>
  2010-05-17 23:17   ` Re: which function should i invoke to create a table and insert tuples? sunpeng <bluevaley@gmail.com>
@ 2010-05-17 23:38     ` John R Pierce <pierce@hogranch.com>
  0 siblings, 0 replies; 6+ messages in thread

From: John R Pierce @ 2010-05-17 23:38 UTC (permalink / raw)
  To: 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.




^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2010-05-17 23:38 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-05-17 14:31 which function should i invoke to create a table and insert tuples? sunpeng <bluevaley@gmail.com>
2010-05-17 14:43 ` Thom Brown <thombrown@gmail.com>
2010-05-17 15:04   ` Thom Brown <thombrown@gmail.com>
2010-05-17 22:19 ` Guy Rouillier <guyr-ml1@burntmail.com>
2010-05-17 23:17   ` sunpeng <bluevaley@gmail.com>
2010-05-17 23:38     ` John R Pierce <pierce@hogranch.com>

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