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

Re: Problem with plpython

From: Justin Pasher <justinp(at)newmediagateway(dot)com>
To: Steve Erickson <serickson(at)digitiliti(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Problem with plpython
Date: 2009-10-30 22:35:24
Message-ID: 4AEB6A2C.2040903@newmediagateway.com (view raw or flat)
Thread:
Lists: pgsql-general
Steve Erickson wrote:
> I'm running PostgreSQL 8.3 with pl/python 8.3.  I am getting a 
> different date/time format when executing the below examples.  The 
> results are the same whether I use os.popen or os.system.  In 
> plpython, I run:
>   import os
>   cmd = 'ls -al /var/log/messages > /var/tmp/log'
>   x = os.popen(cmd)
>   for aline in x.readlines():
>       plpy.notice('aline = %s', aline)
>
> and the contents of /var/tmp/log are "-rw-r----- 1 syslog adm 495523 
> Oct 30 11:52 /var/log/messages
>
> When, within Python, I run:
> >>> cmd = 'ls -al /var/log/messages > /var/tmp/log'
> >>> x = os.popen(cmd)
> >>> for aline in x.readlines():
> ...   print aline
>
> the contents of /var/tmp/log are "-rw-r----- 1 syslog adm 23591 
> 2009-10-30 13:03 /var/log/messages
>
> How, using plpython, can I get the output date/time in the same format 
> as when executing from within python itself?

Different locale settings will produce different formatting for the ls 
command. For example...


[justinp(at)justinp /tmp/test]$ LANG=en_US.UTF-8 ls -l
total 0
-rw-rw-r-- 1 justinp justinp 0 2009-10-30 17:32 aa
-rw-rw-r-- 1 justinp justinp 0 2009-10-30 17:32 bb
-rw-rw-r-- 1 justinp justinp 0 2009-10-30 17:32 cc

[justinp(at)justinp /tmp/test]$ LANG=C ls -l
total 0
-rw-rw-r-- 1 justinp justinp 0 Oct 30 17:32 aa
-rw-rw-r-- 1 justinp justinp 0 Oct 30 17:32 bb
-rw-rw-r-- 1 justinp justinp 0 Oct 30 17:32 cc


It seems to me that you can just override the LANG variable directly in 
your call to ls, since it's just running a shell command.


-- 
Justin Pasher

In response to

pgsql-general by date

Next:From: db deDate: 2009-10-30 22:41:54
Subject: pg_start_backup question
Previous:From: Mark Morgan LloydDate: 2009-10-30 22:23:46
Subject: Re: CREATE TABLE LIKE and SERIAL

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