Re: Why this query does not work? - Mailing list pgsql-sql

From A.Bhuvaneswaran
Subject Re: Why this query does not work?
Date
Msg-id Pine.LNX.4.44.0305131338400.9559-100000@Bhuvan.bksys.co.in
Whole thread Raw
In response to Why this query does not work?  ("Katka a Daniel Dunajsky" <daniel_katka@hotmail.com>)
List pgsql-sql
> service0=#
> service0=# SELECT DISTINCT machine_id
> service0-# FROM                   user_sessions
> service0-# WHERE                 TO_CHAR(session_start, 'Month') = 'April';
> 
> machine_id
> ------------
> (0 rows)
> 

Since to_char function pads space to the value returned. The length of the 
return value of to_char function is 9. It is mentioned in the document, 
please refer the below link for details:

http://www.postgresql.org/docs/view.php?version=7.3&idoc=1&file=functions-formatting.html

You can use rtrim to get rid of your problem. 

=> select distinct machine_id from user_sessions where rtrim (to_char
(session_start, 'Month')) = 'April';

regards,
bhuvaneswaran



pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Why this query does not work?
Next
From: "Ryan"
Date:
Subject: N all-way relationship