From: | Gaetano Mendola <mendola(at)bigfoot(dot)com> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: Cast |
Date: | 2004-09-08 23:18:36 |
Message-ID: | cho411$977$1@floppy.pyrenet.fr |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Eduardo Vázquez Rodríguez wrote:
> 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) ...
> 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
From | Date | Subject | |
---|---|---|---|
Next Message | Pradeepkumar, Pyatalo (IE10) | 2004-09-09 14:13:50 | how to overwrite tuples in a table |
Previous Message | Eduardo Vázquez Rodríguez | 2004-09-08 21:29:26 | Cast |