Auto convert for type?

Поиск
Список
Период
Сортировка
От karly@kipshouse.org
Тема Auto convert for type?
Дата
Msg-id 20060328121306.A21900@kipshouse.org
обсуждение исходный текст
Ответы Re: Auto convert for type?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
Many of my tables have a timestamp column, which I store as
TIMESTAMP WITH TIME ZONE.  Often I only want to return the date from
this field, and it may need a specific format.

All of the queries are passed through PLpqsql functions that return
either a record or a set of records.  I find if I declare the date
field in the return record as type DATE, then the conversion
happens automatically, which is nice, but the format is whatever
datestyle is set to, which isn't what I want.

I can create the date field in the record as TEXT, then use
to_char() to convert it, but I have to do that in every function.

Ideally I could do something like

CREATE TYPE return AS (..., mydate to_char(DATE, 'mm/dd/yy'));


but that syntax doesn't work.  I thought I might be able to create
my own type, and have an implicit conversion of DATE, but I read

http://www.postgresql.org/docs/8.0/interactive/typeconv.html

and found this line


   User-defined types are not related. Currently, PostgreSQL does not
   have information available to it on relationships between types,
   other than hardcoded heuristics for built-in types and implicit
   relationships based on available functions and casts.

Is there another way to solve this?

Thanks

-karl

PS Now when I type pgsql, I think "PigSqueal"  Thanks a lot!  {-;

В списке pgsql-general по дате отправления:

Предыдущее
От: Guy Fraser
Дата:
Сообщение: Re: Advantages of PostgreSQL over MySQL 5.0
Следующее
От: Ron Mayer
Дата:
Сообщение: Re: FAQ 1.1