Skip site navigation (1) Skip section navigation (2)

Re: Auto-formatting timestamps?

From: "Peter Koczan" <pjkoczan(at)gmail(dot)com>
To: "Mag Gam" <magawake(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Auto-formatting timestamps?
Date: 2008-05-14 15:46:09
Message-ID: 4544e0330805140846l4cfa004fx9550cc063f1ab535@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-sql
On Tue, May 13, 2008 at 5:54 PM, Mag Gam <magawake(at)gmail(dot)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

In response to

Responses

pgsql-sql by date

Next:From: Alvaro HerreraDate: 2008-05-14 15:59:36
Subject: Re: Auto-formatting timestamps?
Previous:From: Robins TharakanDate: 2008-05-14 10:01:54
Subject: Re: Add a ROWCOUNT to the output of a select.

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group