Jonathan Levin's Axioms

Ideas, Rants, Theories vs Getting Things Done

1:55 PM

Useful ways of using Views

Posted by Jonathan |

Here are a few ways I found Views to be useful for me.


Data Cleansing

If I have a column that needs to be cleaned or tested in some way. For example:

Select mycolumn, if(mycolumn is null, TRUE, FALSE) as mycolumnisnull from mytable
This example is not that amazing, but it lets you place conditions for the data. Then instead of re-writing these conditions in your application layer, you can re-use the View from the database.
Another example:
Select email, regex ['some amazing email verification/cleaning regex line'] as cleaned_emails from emails
Here again, we have some condition that placed in the database. We can now call the emails table and tell it to give us only the cleaned emails according to the defined conditions.


Decision Making

You can place some business logic in your Views. I wrote about it in my blog before.
This time I will just use an example:

Select business_loan, if (business_loan > 30000, 'Allow Discount', 'No Discount') as discount from loans
So here, you have an embedded rule that says if the loan is over 30,000, then give a discount. Otherwise, no discount.
There are advantages and disadvantages to using business rules in your database. One advantage is the visual way of verifying that your code is working. You can see next to your data if your code works or if you need to make changes.


Displaying parts of many-column tables

Very simply, if you know you only need a few columns from a table with many columns, you can just specify it in a View. It just keeps things tidier.

Create View contact_details
Select col11 as firstname, col52 as lastname, col37 phonenumber from 100columntable
I have used this (a lot) for finding tables to extract data from when I did some ETL-data warehouse work. This is an example:

Create View src_thetableiwaslookingfor
Select * from database1.tablethatiwant
This helped me a lot in the past and also helped when I worked with other developers on the same project. We just all used the same interfaces (Views).


Fashioning your data

You can use some basic text manipulation on your data to help you display it better.
For example:

Select concat(title,'. ',firstname, ' ', lastname) as fullname from contact_details.
Here, we just added the title, first name and last name into one string (example, Mr. John Smith).
If you really want to go crazy, you can do this

Create View HTML_export
Select concat('[tr] [td] ',firstname,'[/td] [td] ',lastname,'[/td] [/tr] ') as list from contact_details

So, if in the future you want to get a quick list of all the contact names in HTML format, you can just use the View.


Conclusion
Views are very useful :)
Especially if you dislike long-winded languages when you can do it in 1 line of SQL.

I plan on writing a more detailed article soon about this topic

3:30 PM

A Blog about Blogging

Posted by Jonathan |

Many of you may have already noticed that blogs are becoming more and more influential as mediums of information. I personally read tens of blogs everyday to keep up with events.

But who decided that blogs are good sources of information?
After all, a blog is someone's opinion. It might be a better educated opinion with more facts then other opinions, but its still someone's opinion.
A blog can be defined as:

Short for "Web log," a specialized site that allows an individual or group of individuals to share a running log of events and personal insights with online audiences.

News

News is still someone's opinion. News companies try to be neutral and say that they report the news the way it is. But anyone probably knows that if they open the TV to a certain news channel, they will see the news in a different way then other channels.
Whether it be if the news channel is usually more right, more left, if the news anchors are tougher then news anchors on other channels, etc..
So there is no "actual" news, there is just how people see the world. Truth is relative to how you see the facts.
In a sense, you can validate blogs as being reasonably "true" by saying that news channels are not 100% "true" anyway.



Chatting with Friends

But not everyone is a news journalist. So what motivates people to write blogs?
Obviously, some people have different reasons. But since its my blog, I will express my opinion to what I think it is.
I think that people like to chat with their friends or other people and share ideas.
It is always nice to talk to a friend who thinks a bit like you and discuss issues that you find interesting.
This is where I think the motivation lies. People want to share ideas and instead of maybe sharing it with one person, they can share it with many people. People who think this issue is interesting. People who either want to learn the issue or people who already know enough about the issue to comment on it.


Facts and Opinions

Opinions are ways of trying to understand the world around us. If there were facts to help us understand the world around us, then we don't need someone's opinion about the issue, we already know or can find out.
If however, there is no formal way of finding out something, we use informal ways. We have opinions about things because we don't have any other formal way of understanding them. We like to give our opinions and discuss them to either affirm them with other people (if they agree) or change them, if we are found out to be wrong.
In this spirit of co-operation, we discover new things when we discuss our opinions.


My Opinion

I think blogs are now at a very mature stage. Already, blogs are compared to news channels and news channels reference blogs some of the time.
A good point to take from this, I think, is that even with news, its important to remember that its still someone's opinion. Its always good to take many different opinions from different sources as well as share your own opinions before coming to your own conclusions.
And its even more important to note, that a lot of our current conclusions are based on opinions. With that, we should be open to new opinions that could possibly change our previous conclusions.

Subscribe