Thread: cast int to float
Hi, I'm creating a new database-item by dividing two existing items. When these items are initially declared as float, there is no problem. On the other hand, when they are declared as int initially and later converted to float, I get the error: float8div: divide by zero error. Maybe I didn't do the casting right. This is what I did: ((cast(item1 as float))/(cast(item2 as float) + cast (item3 as float))) as item4. I played around with putting the brackets at different places, but every time got the same error message. Hopefully someone knows what I should do, Thanks Sheila _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.
Works for me... fbax=# create table sheila (item1 int, item2 int, item3 int); CREATE fbax=# insert into sheila values (1, 2, 4); INSERT 5971355 1 fbax=# select ((cast(item1 as float))/(cast(item2 as float) + cast (item3 as float))) as item4 from sheila; item4 ------------------- 0.166666666666667 (1 row) Perhaps you have a row in your table where item2+item3 = 0? Frank At 10:26 PM 12/29/01 +0000, sheila timp wrote: >Hi, > >I'm creating a new database-item by dividing two existing items. When these >items are initially declared as float, there is no problem. On the other >hand, when they are declared as int initially and later converted to float, >I get the error: float8div: divide by zero error. Maybe I didn't do the >casting right. This is what I did: > >((cast(item1 as float))/(cast(item2 as float) + cast (item3 as float))) as >item4. > >I played around with putting the brackets at different places, but every >time got the same error message. >Hopefully someone knows what I should do, > >Thanks Sheila > >_________________________________________________________________ >Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp. > > >---------------------------(end of broadcast)--------------------------- >TIP 3: if posting/reading through Usenet, please send an appropriate >subscribe-nomail command to majordomo@postgresql.org so that your >message can get through to the mailing list cleanly >
Is anyone else out there trying to get this combo to work? Anyone know anyone who might be working on this combo? I got all the pieces compiled (Python 2.2b3, MacOSX 10.1, PostgreSQL 7.2b3, mx.DateTime 2.0.2). Python and PostgreSQL are both working, but when I try to connect to the DB from Python I get 'Connection refused' and it asks if the server is accepting TCP/IP connections on port 5432. If I give psql that as the explicit port it does just fine. I also tried moving to a different port and changing the call to _pg.connect, but still no joy. Again psql does just fine. BTW, I built Python as a Framework. I've downloaded new latest and greatest (Python 2.2, MacOSX 10.1.2, PostgreSQL 7.2b4, mx.DateTime 2.0.3), but I'm not terribly hopefully. Oh, one other note, I have confirmed that python can handle sockets by setting up pydoc as an http server and accessing it from Netscape. Any suggestions are most welcome. Thanks! -Nathan
Nathan Wilson <velosa@cinenet.net> writes: > I got all the pieces compiled (Python 2.2b3, MacOSX 10.1, PostgreSQL > 7.2b3, mx.DateTime 2.0.2). Python and PostgreSQL are both working, but > when I try to connect to the DB from Python I get 'Connection refused' and > it asks if the server is accepting TCP/IP connections on port 5432. If I > give psql that as the explicit port it does just fine. Is it possible that in the Python case, PG sees the connection as coming from your actual IP address and not from 127.0.0.1? You might try adding an entry to pg_hba.conf for your machine's IP address. (Don't forget that 7.2 requires you to SIGHUP the postmaster to get it to notice pg_hba.conf changes.) regards, tom lane
Thanks for the reply. The problem was that I wasn't giving postmaster the '-i' flag. Thanks to Aarni for suggesting this solution. Enjoy! -Nathan On Fri, 4 Jan 2002, Tom Lane wrote: > Nathan Wilson <velosa@cinenet.net> writes: > > I got all the pieces compiled (Python 2.2b3, MacOSX 10.1, PostgreSQL > > 7.2b3, mx.DateTime 2.0.2). Python and PostgreSQL are both working, but > > when I try to connect to the DB from Python I get 'Connection refused' and > > it asks if the server is accepting TCP/IP connections on port 5432. If I > > give psql that as the explicit port it does just fine. > > Is it possible that in the Python case, PG sees the connection as coming > from your actual IP address and not from 127.0.0.1? You might try > adding an entry to pg_hba.conf for your machine's IP address. > (Don't forget that 7.2 requires you to SIGHUP the postmaster to get it > to notice pg_hba.conf changes.) > > regards, tom lane >
Could somebody give me an example of selects and inserts using the bytea datatype? Is there any thorough documentation of this type online? Thanks, Dan
Hi Gentleman, 1. How to modify a field in the table structure, such I have a filed name 'userid', its type is serial, now I want to change ti to varchar? 2. How to delete a field in the table structure? Terry
Unfortunately there isn't really a good way to do this in PostgreSQL. What you are probably going to end up doing is creating a temporary table with the new schema that you want, copying that data to this new table with an 'insert into' query, delete the old table, and rename the new table. You will probably also want to get rid of the sequence object that your serial type created, and heaven help you if you had a pile of triggers set for this table. Good Luck, Jason "Terry BD7NQ" <bd7nq@hellocq.net> writes: > Hi Gentleman, > > 1. How to modify a field in the table structure, such I have a filed name > 'userid', its type is serial, now I want to change ti to varchar? > 2. How to delete a field in the table structure? > > Terry > > > ---------------------------(end of broadcast)--------------------------- > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org