like '%' works as expected for varchar datatype and not works for char datatype in PostgreSQL.
Created a table as below in PostgreSQL:
create table movie(movie_name varchar(20), director char(20));
[Note: movie_name is varchar type and director is char type]
and inserted few rows using the below query.
insert into movie values('JaiBhim', 'Gnanavel');
insert into movie values('Dharbar', 'ARM');
After this, I used the below select query with '%'.
select *
from movie
where movie_name like '%m';
I got correct row details. [JaiBhim and Gnanavel].
I used another select query with '%' as below.
select *
from movie
where director like '%M';
For this I expected one row should be returned but it returned 0 rows.
For varchar, 'like %' gives correct result and for char datatype it is not giving.
Is it the expected behaviour?
%Mis not taking into account the spaces after theM, try%M%or `select * from movie where trim(director) like '%M'