Can some explain to me why this comparison in postgresql is not working the way I want it to?
So I have a database called customer and it has the columns of customerid, firstname, lastname, phone, and city.. Each one of these columns is a Character(50). I want to find only customers from a certain city and ran multiple queries trying to figure out how to select a certain city.. and I feel like this is going to be a simple answer but I am pretty new to sql querying.
The first query I ran is this
FROM customer c
WHERE c.city = 'Denver'
character pads all values to the defined length. So
'Denver' is stored as
Values of type character are physically padded with spaces to the specified width n, and are stored and displayed that way
This is how this data type is defined by the SQL standard. It is an ancient left over.
In a nutshell: never use
character. It is always better to use
varchar (this is true for essentially every SQL database - and even more so for Postgres).