Re: Auto-formatting timestamps? - Mailing list pgsql-sql

From Mag Gam
Subject Re: Auto-formatting timestamps?
Date
Msg-id 1cbd6f830805141946w5b783813x2708c667a59e7639@mail.gmail.com
Whole thread Raw
In response to Re: Auto-formatting timestamps?  ("Peter Koczan" <pjkoczan@gmail.com>)
List pgsql-sql
But why not make a view similar to, select * from checkoutdate do select * from checkoutdate_special_view

You don't have to do it for each table, you just do it for your source table, and use the view to manipulate stuff...

If you have many tables like that, you can create a view for each of them, sure its a lot of work, but its worth it....

HTH


On Wed, May 14, 2008 at 11:46 AM, Peter Koczan <pjkoczan@gmail.com> wrote:
On Tue, May 13, 2008 at 5:54 PM, Mag Gam <magawake@gmail.com> wrote:
> Why not create a view?

That's a possibility, but the issue is that the output formatting is
bound to a data type (timestamp), not one or two particular tables.
Trying to create a view for all the tables with timestamps (and
creating appropriate rules for updating views) would be a huge
administrative PITA.

> > Hi all,
> >
> > I'm undergoing a port from an old Sybase database to Postgres. It's
> > going surprisingly well, but I have a question regarding formatting of
> > timestamps.
> >
> > In Sybase, we get:
> > :> select date from checkoutdate;
> > date
> > 'May  1 2001 12:00AM'
> > ...
> >
> > In Postgres:
> > => select date from checkoutdate;
> >       date
> > ---------------------
> >  2001-05-01 00:00:00
> > ...
> >
> > I can properly format it using to_char:
> > => select to_char(date, 'Mon DD YYYY HH:MIAM') as date from checkoutdate;
> >       date
> > ---------------------
> >  May 01 2001 12:00AM
> > ...
> >
> > Short of creating a wrapper type for timestamp (which seems like
> > overkill just for modifying the output function), is there a way to
> > output the Sybase format automatically (i.e. without a call to
> > to_char)?
> >
> > I've found some code that actually somewhat depends on this format,
> > and one of my goals in this port is to change as little client code as
> > possible. Is it possible to automatically change the output like this,
> > preferably on a per-connection basis? I found stuff regarding the
> > datestyle parameter in the docs, but that doesn't quite do what I'd
> > like.
> >
> > Thanks much,
> > Peter

pgsql-sql by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Auto-formatting timestamps?
Next
From:
Date:
Subject: Query tuning