dbTalk Databases Forums  

Re: Cast

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Re: Cast in the comp.databases.postgresql.novice forum.



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

Default Re: Cast - 09-08-2004 , 06:18 PM






Eduardo Vázquez Rodríguez wrote:

Quote:
I made I mistake choosing the data types in my database I try to run a
query that look like this
Duration data type is varchar

SELECT name, SUM(duration) AS total
FROM table
GROUP BY name
HAVING name != 'John'

I get the following error:
ERROR: function sum(character varying) does not exist
HINT: No function matches the given name and argument types. You may
need to add explicit type casts.

1. How can I made a cast on the query from varchar to int?
Try with:

.... SUM(duration::integer) ...


Quote:
2. If I change the datatype on the database from varchar to int, do I
loose all the data on that field?
You can create a new integer column, copy all datas from the old
VARCHAR column to the new one and with a rename column and a remove column
you finish...


Regards
Gaetano Mendola




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.