Re: convert to a string - Mailing list pgsql-sql

From A. Kretschmer
Subject Re: convert to a string
Date
Msg-id 20070306135636.GM10330@a-kretschmer.de
Whole thread Raw
In response to convert to a string  ("Shavonne Marietta Wijesinghe" <shavonne.marietta@studioform.it>)
List pgsql-sql
am  Tue, dem 06.03.2007, um 14:42:53 +0100 mailte Shavonne Marietta Wijesinghe folgendes:
> Hello
> 
> i have a column N_GEN in postgreSql defined as text. In this coloumn i insert a
> number 10

Why do you store numbers as text?


> 
> N_GEN (text) = 10
>  
>  
> on error resume next
>   Set oRs = oConn.Execute("SELECT N_GEN FROM MyTable ORDER BY N_GEN DESC")
>  
> But it doesn't add the 1 to my N_GEN

You can't add a number to a string.


> How can i set the Recordset to convert the string to a number and then add 1 to
> it??

You can try to cast it to int:

test=# select '10'::text;text
------10
(1 row)

test=*# select '10'::text::int;int4
------  10
(1 row)


In your Query, change 'SELECT N_GEN FROM' to 'SELECT N_GEN::int FROM'.


Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net


pgsql-sql by date:

Previous
From: "Ezequias Rodrigues da Rocha"
Date:
Subject: Re: Time of executed query
Next
From: "Shoaib Mir"
Date:
Subject: Re: Time of executed query