dbTalk Databases Forums  

convert character varying to int

comp.databases.postgresql comp.databases.postgresql


Discuss convert character varying to int in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
RJ
 
Posts: n/a

Default convert character varying to int - 04-18-2008 , 09:04 PM






Hi,

I'm using postgres sql 8.1x

anyone can help convert a character varying to int?

I have a table with :
attribute | character varying(20)

and I need to convert it to numbers so I can do some calculation.

tried
select cast(privilege.value as int)

didn't work.

please help.

Thanks

Reply With Quote
  #2  
Old   
Andreas Kretschmer
 
Posts: n/a

Default Re: convert character varying to int - 04-19-2008 , 11:14 AM






begin RJ wrote:
Quote:
Hi,

I'm using postgres sql 8.1x

anyone can help convert a character varying to int?

I have a table with :
attribute | character varying(20)

and I need to convert it to numbers so I can do some calculation.

tried
select cast(privilege.value as int)
simple example:

test=*# select regexp_replace('abc123def','[^0-9]','','g')::int * 10;
?column?
----------
1230




end
Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknown)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°


Reply With Quote
  #3  
Old   
Andreas Kretschmer
 
Posts: n/a

Default Re: convert character varying to int - 04-19-2008 , 11:14 AM



begin RJ wrote:
Quote:
Hi,

I'm using postgres sql 8.1x

anyone can help convert a character varying to int?

I have a table with :
attribute | character varying(20)

and I need to convert it to numbers so I can do some calculation.

tried
select cast(privilege.value as int)
simple example:

test=*# select regexp_replace('abc123def','[^0-9]','','g')::int * 10;
?column?
----------
1230




end
Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknown)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°


Reply With Quote
  #4  
Old   
Andreas Kretschmer
 
Posts: n/a

Default Re: convert character varying to int - 04-19-2008 , 11:14 AM



begin RJ wrote:
Quote:
Hi,

I'm using postgres sql 8.1x

anyone can help convert a character varying to int?

I have a table with :
attribute | character varying(20)

and I need to convert it to numbers so I can do some calculation.

tried
select cast(privilege.value as int)
simple example:

test=*# select regexp_replace('abc123def','[^0-9]','','g')::int * 10;
?column?
----------
1230




end
Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknown)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°


Reply With Quote
  #5  
Old   
Andreas Kretschmer
 
Posts: n/a

Default Re: convert character varying to int - 04-19-2008 , 11:14 AM



begin RJ wrote:
Quote:
Hi,

I'm using postgres sql 8.1x

anyone can help convert a character varying to int?

I have a table with :
attribute | character varying(20)

and I need to convert it to numbers so I can do some calculation.

tried
select cast(privilege.value as int)
simple example:

test=*# select regexp_replace('abc123def','[^0-9]','','g')::int * 10;
?column?
----------
1230




end
Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknown)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°


Reply With Quote
  #6  
Old   
Andreas Kretschmer
 
Posts: n/a

Default Re: convert character varying to int - 04-19-2008 , 11:14 AM



begin RJ wrote:
Quote:
Hi,

I'm using postgres sql 8.1x

anyone can help convert a character varying to int?

I have a table with :
attribute | character varying(20)

and I need to convert it to numbers so I can do some calculation.

tried
select cast(privilege.value as int)
simple example:

test=*# select regexp_replace('abc123def','[^0-9]','','g')::int * 10;
?column?
----------
1230




end
Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknown)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°


Reply With Quote
  #7  
Old   
Andreas Kretschmer
 
Posts: n/a

Default Re: convert character varying to int - 04-19-2008 , 11:14 AM



begin RJ wrote:
Quote:
Hi,

I'm using postgres sql 8.1x

anyone can help convert a character varying to int?

I have a table with :
attribute | character varying(20)

and I need to convert it to numbers so I can do some calculation.

tried
select cast(privilege.value as int)
simple example:

test=*# select regexp_replace('abc123def','[^0-9]','','g')::int * 10;
?column?
----------
1230




end
Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknown)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°


Reply With Quote
  #8  
Old   
Andreas Kretschmer
 
Posts: n/a

Default Re: convert character varying to int - 04-19-2008 , 11:14 AM



begin RJ wrote:
Quote:
Hi,

I'm using postgres sql 8.1x

anyone can help convert a character varying to int?

I have a table with :
attribute | character varying(20)

and I need to convert it to numbers so I can do some calculation.

tried
select cast(privilege.value as int)
simple example:

test=*# select regexp_replace('abc123def','[^0-9]','','g')::int * 10;
?column?
----------
1230




end
Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknown)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°


Reply With Quote
  #9  
Old   
Andreas Kretschmer
 
Posts: n/a

Default Re: convert character varying to int - 04-19-2008 , 11:14 AM



begin RJ wrote:
Quote:
Hi,

I'm using postgres sql 8.1x

anyone can help convert a character varying to int?

I have a table with :
attribute | character varying(20)

and I need to convert it to numbers so I can do some calculation.

tried
select cast(privilege.value as int)
simple example:

test=*# select regexp_replace('abc123def','[^0-9]','','g')::int * 10;
?column?
----------
1230




end
Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknown)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°


Reply With Quote
  #10  
Old   
EricF
 
Posts: n/a

Default Re: convert character varying to int - 04-19-2008 , 11:24 PM



In article <2cipd5-ttt.ln1 (AT) news (DOT) a-kretschmer.de>, Andreas Kretschmer <akretschmer (AT) spamfence (DOT) net> wrote:
Quote:
begin RJ wrote:
Hi,

I'm using postgres sql 8.1x

anyone can help convert a character varying to int?

I have a table with :
attribute | character varying(20)

and I need to convert it to numbers so I can do some calculation.

tried
select cast(privilege.value as int)

simple example:

test=*# select regexp_replace('abc123def','[^0-9]','','g')::int * 10;
?column?
----------
1230




end
Andreas
It's not too clear what you want. If attribute only contains numbers it's
easier than Andreas' example:

select (CAST(attribute as int) *2) from ...

Eric


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.