MySQL Forums
Forum List  »  Newbie

Re: Select * with a function applied to one column
Posted by: Dean Richert
Date: December 04, 2014 02:49AM

I realized my post may have been (very) hard to understand due to a missing word. Sorry about that, I am glad you understood it. Just in case someone else is reading this though, I hope this is clearer (the forum does not allow me to edit the original post):

This line:
>The catch is that it would be vastly preferable to me to have the column that has the function performed a column with the same name as the column the function was performed on, instead of FUNCTION([column_name]). (So that column ip is returned as column ip, not column INET_NTOA(ip)) I tried:

Should be:

>The catch is that it would be vastly preferable to me to have the column that has the function performed on its values be returned as a column with the same name, instead of being returned as FUNCTION([column_name]). (So that column ip is returned as column ip, not column INET_NTOA(ip)) I tried:

That said, I do make a habit of never using a SELECT * unless I really do make use of every column, but in this case, I actually do (The code that uses this statement build an object out of the row returned which must contain the value of every field for a row.)

I don't know what you meant whensay "index-based column processing." Do you mean making use of the result set based a column's index number, and not the name of the column itself? If that is what you mean, I do not do that, in fact the code that makes use of the result set explicitly references each column's name, which is why it is preferable to me to NOT have to change the code, but instead just change the query.

This version requires me to change every reference to column 'ip' to 'converted_ip':
SELECT geo.*, INET_NTOA(ip) AS converted_ip FROM geo WHERE uid = 100;

And this version will be just an obvious bug generator, because the result set has two columns with the exact same name (ip)
SELECT geo.*, INET_NTOA(ip) AS ip FROM geo WHERE uid = 100;

Ideally, I could replace the ip column in the result set with the output of the INET_NTOA(ip) function, instead of having a new column named INET_NTOA(ip).

I'd like to be able to just specify every column's name, but assuming I can't do that, is there an alternative to get the results I wanted?

Options: ReplyQuote


Subject
Written By
Posted
Re: Select * with a function applied to one column
December 04, 2014 02:49AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.