Unix Technical Forum

Help in dynamic execution in plpgsql

This is a discussion on Help in dynamic execution in plpgsql within the pgsql Novice forums, part of the PostgreSQL category; --> I have a schema schema_1 and a table named NMSAutomaticWorkstation. I would like to run dynamically data from this ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 08:31 PM
Stefan.Ardeleanu@siveco.ro
 
Posts: n/a
Default Help in dynamic execution in plpgsql

I have a schema schema_1 and a table named NMSAutomaticWorkstation.
I would like to run dynamically data from this table changing all the
possible clauses (select, where, order by).
The function is named NMSAutomaticWorkstation_rwc (NMSAutomaticWorkstation
read by where clause).
I have a string and I want to execute the string. Can you tell me how can I
get the proper result set (the mistakes in the body of the function or the
mistakes in the calling statement).
Thanks in advanced. Here is the code.

SET SEARCH_PATH TO schema_1;

CREATE OR REPLACE FUNCTION NMSAutomaticWorkstation_rwc (VARCHAR (500),
VARCHAR (500), VARCHAR (500)) RETURNS VOID AS $$
DECLARE
v_selectList ALIAS FOR $1;
v_whereClause ALIAS FOR $2;
v_orderByClause ALIAS FOR $3;
v_id INTEGER;
v_SQL VARCHAR (4000);
BEGIN
v_SQL := 'SELECT ' || v_selectList || ' FROM NMSAutomaticWorkstation
';
IF v_whereClause IS NOT NULL THEN
v_SQL := v_SQL || ' WHERE ' || v_whereClause;
END IF;

IF v_orderByClause IS NOT NULL THEN
v_SQL := v_SQL || ' ORDER BY ' || v_orderByClause;
END IF;

v_SQL := v_SQL || ';';

EXECUTE v_SQL;

RETURN;
END;
$$ LANGUAGE plpgsql;

select NMSAutomaticWorkstation_rwc ('*', '1=1', NULL)

Stefan Ardeleanu


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:00 AM.


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