Re: Why this query does not work?

From: "A(dot)Bhuvaneswaran" <bhuvansql(at)myrealbox(dot)com>
To: Katka a Daniel Dunajsky <daniel_katka(at)hotmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Why this query does not work?
Date: 2003-05-13 08:12:20
Message-ID: Pine.LNX.4.44.0305131338400.9559-100000@Bhuvan.bksys.co.in
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message SEB Menard 2003-05-13 12:15:44 Questions for experts
Previous Message A.Bhuvaneswaran 2003-05-13 05:57:33 Re: select 3 characters