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

Re: [INTERFACES] Questions about INSERT INTO!

From: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
To: "Anna Langer" <anna_langer(at)hotmail(dot)com>, pgsql-interfaces(at)postgreSQL(dot)org
Subject: Re: [INTERFACES] Questions about INSERT INTO!
Date: 1999-05-25 09:45:16
Message-ID: l03130300b3701f13c24c@[] (view raw, whole thread or download thread mbox)
Lists: 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 Maoz, Internet developer.
Open University of Israel - Telem project

In response to

pgsql-interfaces by date

Next:From: Herouth MaozDate: 1999-05-25 10:24:24
Subject: Re: [GENERAL] JDBC and insert - stack overflow
Previous:From: Michael MeskesDate: 1999-05-25 07:55:17
Subject: Re: [INTERFACES] ECPG feature

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