pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedQuestions about INSERT INTO!
2+ messages / 2 participants
[nested] [flat]
* Questions about INSERT INTO!
@ 1999-05-25 00:54 Anna Langer <anna_langer@hotmail.com>
1999-05-25 09:45 ` Re: [INTERFACES] Questions about INSERT INTO! Herouth Maoz <herouth@oumail.openu.ac.il>
0 siblings, 1 reply; 2+ messages in thread
From: Anna Langer @ 1999-05-25 00:54 UTC (permalink / raw)
To: pgsql-interfaces
Hi!
Thanks for all help. It worked very well.
We still have some problems with inserting a datetime into the database.
If we write like this the database accept it:
PQexec(conn, "INSERT INTO test VALUES('23/01/1999 12:03:30');
When we are inserting other values in the database we write like this:
sprintf(command, "INSERT INTO octets VALUES(%d, %d)", a, b);
Now we wonder if we can put the date in to the database in the same way that
we did with the integers? We have tried to make the date to a string, but it
doesn't take it. The errormessage say that the database is of type datetime
and the string is of type int4.
Is there anyone who can help us with this?
Thanks!
Anna and Maria
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: [INTERFACES] Questions about INSERT INTO!
1999-05-25 00:54 Questions about INSERT INTO! Anna Langer <anna_langer@hotmail.com>
@ 1999-05-25 09:45 ` Herouth Maoz <herouth@oumail.openu.ac.il>
0 siblings, 0 replies; 2+ messages in thread
From: Herouth Maoz @ 1999-05-25 09:45 UTC (permalink / raw)
To: Anna Langer <anna_langer@hotmail.com>; pgsql-interfaces
At 10:54 +0300 on 25/05/1999, Anna Langer wrote:
> Now we wonder if we can put the date in to the database in the same way that
> we did with the integers? We have tried to make the date to a string, but it
> doesn't take it. The errormessage say that the database is of type datetime
> and the string is of type int4.
>
> Is there anyone who can help us with this?
>
> Thanks!
You really must learn C. The trick with the %d is the standard way in C of
converting integers into strings. Dates are a bit more complicated. What is
the type you use for dates? time_t? If so, you convert it to string using
ctime(), a function in the standard C library. And then you use sprintf and
place it within single quotes.
It's true for every data type. You have to convert it to string, and then
have that string inserted into the command string using sprintf, with %s
within quotes. In the case of integer, the two steps can be shortened into
one, and you don't need quotes around the value. Same goes for float. Any
other data type needs the two steps and quotes.
Once you master this, remember that if your datatype is string, you have to
make sure every quote within the string is doubled (or preceded with a
backslash, but that's non-standard) before you pass it.
Herouth
--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~1999-05-25 09:45 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-05-25 00:54 Questions about INSERT INTO! Anna Langer <anna_langer@hotmail.com>
1999-05-25 09:45 ` Herouth Maoz <herouth@oumail.openu.ac.il>
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