Unix Technical Forum

Basic problems using plpythonu - bug?

This is a discussion on Basic problems using plpythonu - bug? within the Pgsql General forums, part of the PostgreSQL category; --> I'm trying to do something pretty basic per the documentation using plpython triggers. When I change the "cfgCmd" field ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-09-2008, 08:26 AM
Curt Schwaderer
 
Posts: n/a
Default Basic problems using plpythonu - bug?

I'm trying to do something pretty basic per the documentation using plpython triggers. When I change the "cfgCmd" field in the SysConfig table below, the trigger works fine and if I have a null function that does nothing but write to the pipe, that all works fine. The trouble is when the function attemts to read from the SysConfig database, "cfgCmd" field which tells the function what to do. When I write a value to the SysConfig table, cfgCmd field, the server log says:

ERROR: plppython: function "send_ctl_msg" failed
DETAIL: exceptions.KeyError: 'cfgCmd'

What's a key error? I can't find any documentation on it? Also, when I try to reference TD["old"][<column name>] this gives me an error too. Does this have something to do with the untrusted language part or am I doing something wrong? Thanks much for any help,
Curt

Here is the trigger function:

-- Send Control Message (send_ctl_msg)
CREATE FUNCTION send_ctl_msg() RETURNS trigger AS $$
import os
import os.path

pipe_loc = TD["args"][0]

old = TD["old"]
new = TD["new"]

rv = plpy.execute("SELECT * from ucfg.SysConfig",1)
ens_cmd = rv[0]["cfgCmd"]
plpy.log(cmd)

if os.path.exists(pipe_loc):
pipeout = open(pipe_loc,"w")
print >>pipeout,ens_cmd
else:
plpy.error("Build System cmd FIFO not found. Make sure VMD is running")
$$ LANGUAGE plpythonu;

Here is the table it's trying to access:

CREATE TABLE ucfg.SysConfig (
-- System map selection and running
startupSysMapName VARCHAR(64) REFERENCES ucfg.SysMaps(sysMapName),
-- System map to load and run at system boot.
activeSysMapName VARCHAR(64) REFERENCES ucfg.SysMaps(sysMapName),
-- System map that is currently loaded.
checkSysMapName VARCHAR(64) REFERENCES ucfg.SysMaps(sysMapName),
-- System map to be checked to see if it builds properly
cfgCmd VARCHAR(16), -- ENS configuration control command
-- "NONE", "CHECK", "LOAD", "RUN", "STOP"
);

Here is the trigger function:
CREATE TRIGGER tr_exec
AFTER UPDATE ON ucfg.SysConfig for EACH ROW
EXECUTE PROCEDURE public.send_ctl_msg("/var/ens/cmdfifo");

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-09-2008, 08:26 AM
Michael Fuhr
 
Posts: n/a
Default Re: Basic problems using plpythonu - bug?

On Fri, Feb 17, 2006 at 11:38:21AM -0600, Curt Schwaderer wrote:
> ERROR: plppython: function "send_ctl_msg" failed
> DETAIL: exceptions.KeyError: 'cfgCmd'


You're getting bit by case folding of identifiers. You created
the column as:

> cfgCmd VARCHAR(16), -- ENS configuration control command


Since you didn't quote the identifier it's folded to lowercase, so
when you refer to it as

> ens_cmd = rv[0]["cfgCmd"]


you get a KeyError exception. Try using rv[0]["cfgcmd"]. You might
want to read the documentation about quoted identifiers:

http://www.postgresql.org/docs/8.1/i...AX-IDENTIFIERS

--
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-09-2008, 08:26 AM
Curt Schwaderer
 
Posts: n/a
Default Re: Basic problems using plpythonu - bug?

Thanks a bunch - that cleaned everything up!

Curt

----- Original Message -----
From: "Michael Fuhr" <mike@fuhr.org>
To: "Curt Schwaderer" <curt.schwaderer@mchsi.com>
Cc: <pgsql-general@postgresql.org>
Sent: Friday, February 17, 2006 11:57 AM
Subject: Re: [GENERAL] Basic problems using plpythonu - bug?


> On Fri, Feb 17, 2006 at 11:38:21AM -0600, Curt Schwaderer wrote:
>> ERROR: plppython: function "send_ctl_msg" failed
>> DETAIL: exceptions.KeyError: 'cfgCmd'

>
> You're getting bit by case folding of identifiers. You created
> the column as:
>
>> cfgCmd VARCHAR(16), -- ENS configuration control command

>
> Since you didn't quote the identifier it's folded to lowercase, so
> when you refer to it as
>
>> ens_cmd = rv[0]["cfgCmd"]

>
> you get a KeyError exception. Try using rv[0]["cfgcmd"]. You might
> want to read the documentation about quoted identifiers:
>
> http://www.postgresql.org/docs/8.1/i...AX-IDENTIFIERS
>
> --
> Michael Fuhr



---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:35 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com