Skip site navigation (1) Skip section navigation (2)

Re: [GENERAL] Problems with INSERT INTO?

From: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
To: "Anna Langer" <anna_langer(at)hotmail(dot)com>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: [GENERAL] Problems with INSERT INTO?
Date: 1999-05-24 09:46:18
Message-ID: l03130300b36ecf4b45e8@[147.233.159.109] (view raw, whole thread or download thread mbox)
Thread:
Lists: pgsql-generalpgsql-interfaces
At 12:22 +0300 on 24/05/1999, Anna Langer wrote:


> We are not really sure if this question is right for this mailinglist.
> We have some problem with INSERT INTO and we dont know how to solve it.We
> are writing it in a C-program. We are trying to get an integer from a file
> and put it into a database. And we are sure that we get a interger into our
> program.

The proper mailing list is the "interfaces" list, where I am redirecting
this post now.

> int a=500;
>
> PQexec(conn, "INSERT INTO octets VALUES(a)");
>
>
> But the program works when we do like this:
>
> PQexec(conn, "INSERT INTO octets VALUES(500)");
>
>
> It feels like we need to convert int a in some way, byt we dont know how. We
> are beginners with Postgresql.

This is less on the PostgreSQL side, and more on the C side. Just putting
"a" in a string doesn't tell C to pass the variable a. It just passes the
character "a", right?

What you have to do is pass the value of a as part of the command string.
So you have to make a string out of a. This is usually done with sprintf,
like this:

char command[1000];
int a=500;

sprintf( command, "INSERT INTO octets VALUES(%d)", a );

PQexec( conn, command );

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma



In response to

Responses

pgsql-interfaces by date

Next:From: Simon DrabbleDate: 1999-05-24 13:25:51
Subject: Re: [GENERAL] Problems with INSERT INTO?
Previous:From: Alf LewerkenDate: 1999-05-24 08:08:56
Subject: Error Compiling unixODBC

pgsql-general by date

Next:From: Brett W. McCoyDate: 1999-05-24 11:01:36
Subject: Re: [GENERAL] Full Text Searches
Previous:From: Piotr StelmaszykDate: 1999-05-24 09:37:33
Subject: PL/pgSQL - accessing arrays

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group