Confused by to_char

Started by mikeabout 21 years ago4 messagesgeneral
Jump to latest
#1mike
mike@redtux1.uklinux.net

I am am trying to get a day string from a date using to_char ie:

SELECT date1,ti1 ,to1,ti2,to2,adj,ei,eo,to_char('2005-02-07','Day') FROM
vw_times_list1

however I get

function to_char("unknown", "unknown") is not unique

(using to_date does not recognise the date format)

anyone any ideas what I am doing wrong

#2Ragnar Hafstað
gnari@simnet.is
In reply to: mike (#1)
Re: Confused by to_char

On Tue, 2005-02-08 at 12:28 +0000, mike wrote:

I am am trying to get a day string from a date using to_char ie:

SELECT date1,ti1 ,to1,ti2,to2,adj,ei,eo,to_char('2005-02-07','Day') FROM
vw_times_list1

however I get

function to_char("unknown", "unknown") is not unique

test=# select to_char('2005-02-07'::date,'Day');
to_char
-----------
Monday
(1 row)

gnari

#3Chris Green
chris@areti.co.uk
In reply to: mike (#1)
Re: Confused by to_char

On Tue, Feb 08, 2005 at 12:28:26PM +0000, mike wrote:

I am am trying to get a day string from a date using to_char ie:

SELECT date1,ti1 ,to1,ti2,to2,adj,ei,eo,to_char('2005-02-07','Day') FROM
vw_times_list1

however I get

function to_char("unknown", "unknown") is not unique

(using to_date does not recognise the date format)

anyone any ideas what I am doing wrong

Yes, in a way.

to_char needs two parameters, a pattern and a variable to format
according to the pattern. You've given it a pattern it doesn't
recognise and a constant string which doesn't look like a date.

It needs to look something like:-

to_char(date_time, 'RRRRMMDDHH24MISS')

This is an Oracle example so I'm not sure if the pattern is exactly
right but it'll look something like this. Look at the documentation
for to_char() for the format of the pattern. date_time is a date
column in your database.

--
Chris Green (chris@areti.co.uk)

"Never ascribe to malice that which can be explained by incompetence."

#4mike
mike@redtux1.uklinux.net
In reply to: Ragnar Hafstað (#2)
Re: Confused by to_char

On Tue, 2005-02-08 at 13:00 +0000, Ragnar Hafstað wrote:

On Tue, 2005-02-08 at 12:28 +0000, mike wrote:

I am am trying to get a day string from a date using to_char ie:

SELECT date1,ti1 ,to1,ti2,to2,adj,ei,eo,to_char('2005-02-07','Day') FROM
vw_times_list1

however I get

function to_char("unknown", "unknown") is not unique

test=# select to_char('2005-02-07'::date,'Day');
to_char
-----------
Monday
(1 row)

thanks for this - I found the solution to my immediate problem by
looking through a dump for to_char and found the function I was looking
for at the moment (dayname) but this will be useful for the general case

Mike

Show quoted text

gnari

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org