Thread: Datestyle and Postmaster

Datestyle and Postmaster

From
Jason Everett
Date:
Greetings,

I have upgraded Postgres to v7.0.3  on a linux machine and have run into
some trouble. I am using a very old program that I didn't write but it
is having some trouble with the way Postgres is handling the date.  It
would be easiest for me to have Postgres handle the date in this format:
MM-DD-YYYY.

Is it possible to have postmaster control the datestyle other than -e
for the European style?  I have gotten "SET DATESTYLE TO 'SQL, US'" to
work using psql but I'm not quite sure how to get my programs to do the
same (other than rewrite them to use the ISO, US style).  Is there a way
I could use the -o option in postmaster?

Is there a function I could call that I could use to change this behavior?

What version of postgres supported MM-DD-YYYY as the default?  Does
v.6.5.3 have this behavior?  If so, I do have a copy of this with my
data in this format.

Thanks for your help,
Jason

Re: Datestyle and Postmaster

From
Marc SCHAEFER
Date:
On Thu, 16 Nov 2000, Jason Everett wrote:

> work using psql but I'm not quite sure how to get my programs to do the
> same (other than rewrite them to use the ISO, US style).  Is there a way

I use this in my open_database() Perl function:

# NAME
#    open_database
# DESCRIPTION
#    Opens a database and sets up a reasonable set of defaults.
# RESULT
#    The database handle, or undef.
# NOTES
# BUGS
# TODO
sub open_database {
   # NOTES
   #    - We set AutoCommit to 1 (no transactions for now)
   #      and RaiseError to 0, since we check explicitely all
   #      results.
   my $dbh = DBI->connect("dbi:Pg"
                          . ":dbname=$the_database"
                          . ";host=$the_server",
                          $the_user,
                          $the_password,
                          { RaiseError => 0,
                            AutoCommit => 1
                          });

   if (defined($dbh)) {
      # Also sets up reasonable defaults.

      my $result = 0;
      my $sth = $dbh->prepare("SET DATESTYLE=\'ISO\'");
      if (defined($sth)) {
         my $rv = $sth->execute;

         if (defined($rv)) {
            $result = 1;
            undef $rv;
         }

         $sth->finish;
         undef $sth;
      }

      if ($result == 0) {
         undef $dbh;
      }
   }

   return $dbh;
}