473,587 Members | 2,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unable to create a PL/PGSL function : Did I miss something ?

Hello,

I'm trying to build a PL/PGSQL function that will be called by a trigger
which will update a table named 'mview_contacts '. That table plays the
role of a materialized view.

The 'plpgsql' language is installed on that database (there are already
several functions inside) but I don't understand why I can't store that
function in the database.

When I cut/paste the code, psql seems to wait for something at the end:

levure(> ' LANGUAGE 'plpgsql';
levure'>

I've counted 178 ' quotes in that function, so I don't think that is a
missing quote.
There are 38 opening ( and 38 closing ).
All the IF are closed by a END IF.

Do you see what I've missed to get that function to be saved inside the
database ?

CREATE OR REPLACE function update_mview_co ntacts() RETURN OPAQUE AS '
BEGIN
IF TG_OP = ''INSERT'' THEN
-- Add the new contact into the materialized
view

IF TG_RELNAME = ''people'' THEN
EXECUTE ''INSERT INTO mview_contacts
(pk_fk_cnt_id,c nt_name,cnt_typ e,cnt_initial)' ' ||
quote_literal(' VALUES(NEW.pk_f k_cnt_id, (COALESCE(NEW.l _name,\'\') || \'
\' || COALESCE(NEW.f_ name,\'\')),
\'people\',LOWE R(SUBSTR((COALE SCE(NEW.l_name, \'\') || \' \' ||
COALESCE(NEW.f_ name,\'\')), 1, 1)))');
ELSIF TG_RELNAME = ''organizations '' THEN
EXECUTE ''INSERT INTO mview_contacts
(pk_fk_cnt_id,c nt_name,cnt_typ e,cnt_initial)' ' ||
quote_literal(' VALUES(NEW.pk_f k_cnt_id, NEW.org_name,
\'organization\ ',LOWER(SUBSTR( NEW.org_name, 1, 1)))');
ELSE
RAISE EXCEPTION ''The [%] table is
unsupported by this trigger function'', TG_RELNAME;
END IF;
ELSIF TG_OP = ''UPDATE'' THEN
-- Update the contact infos in the materialized
view

IF TG_RELNAME = ''people'' THEN
EXECUTE ''UPDATE mview_contacts SET ''
|| quote_ident('cn t_name') || '' = '' ||
quote_literal(' (COALESCE(l_nam e,\'\') || \' \' ||
COALESCE(f_name ,\'\'))') || '',''
|| quote_ident('cn t_type') || '' = '' ||
quote_literal(' people') || '',''
|| quote_ident('cn t_initial') || '' = ''
|| quote_literal(' LOWER(SUBSTR(NE W.org_name, 1, 1))')
|| '' WHERE mview_contacts. pk_fk_cnt_id
= '' || quote_literal(O LD.pk_fk_cnt_id );
ELSIF TG_RELNAME = ''organizations '' THEN
EXECUTE ''UPDATE mview_contacts SET ''
|| quote_ident('cn t_name') || '' = '' ||
quote_literal(' NEW.org_name') || '',''
|| quote_ident('cn t_type') || '' = '' ||
quote_literal(' organization') || '',''
|| quote_ident('cn t_initial') || '' = ''
|| quote_literal(' LOWER(SUBSTR(NE W.org_name, 1, 1))')
|| '' WHERE mview_contacts. pk_fk_cnt_id
= '' || quote_literal(O LD.pk_fk_cnt_id );
ELSE
RAISE EXCEPTION ''The [%] table is
unsupported by this trigger function'', TG_RELNAME;
END IF;
ELSIF TG_OP = ''DELETE'' THEN
-- Remove the contact from the materialized view

IF TG_RELNAME = ''people'' THEN
EXECUTE ''DELETE mview_contacts WHERE
pk_fk_cnt_id = OLD.pk_fk_cnt_i d'';
ELSIF TG_RELNAME = ''organizations '' THEN
EXECUTE ''DELETE mview_contacts WHERE
pk_fk_cnt_id = OLD.pk_fk_cnt_i d'';
ELSE
RAISE EXCEPTION ''The [%] table is
unsupported by this trigger function'', TG_RELNAME;
END IF;
ELSE
-- Unknown trigger operation
-- ==> Raise an exception
RAISE EXCEPTION ''Unknown trigger function
operation [%]'', TG_OP;
END IF;
END;
' LANGUAGE 'plpgsql';
Thanks you very much in advance for your help.

Regards,

---------------------------------------
Bruno BAGUETTE - pg******@baguet te.net
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 22 '05 #1
1 2415
On Sun, Feb 08, 2004 at 01:47:51AM +0100, Bruno BAGUETTE wrote:
Hello,

I'm trying to build a PL/PGSQL function that will be called by a trigger
which will update a table named 'mview_contacts '. That table plays the
role of a materialized view.

The 'plpgsql' language is installed on that database (there are already
several functions inside) but I don't understand why I can't store that
function in the database.
You forgot to escape some quotes:
quote_literal(' people') || '','' ^ ^ || quote_ident('cn t_initial') || '' = '' ^ ^ || quote_literal(' LOWER(SUBSTR(NE W.org_name, 1, 1))') ^ ^
|| quote_ident('cn t_name') || '' = '' ||
quote_literal(' NEW.org_name') || '',''
|| quote_ident('cn t_type') || '' = '' ||
quote_literal(' organization') || '',''
|| quote_ident('cn t_initial') || '' = ''
|| quote_literal(' LOWER(SUBSTR(NE W.org_name, 1, 1))')
Several in there

Hope this helps,
--
Martijn van Oosterhout <kl*****@svana. org> http://svana.org/kleptog/ (... have gone from d-i being barely usable even by its developers
anywhere, to being about 20% done. Sweet. And the last 80% usually takes
20% of the time, too, right?) -- Anthony Towns, debian-devel-announce


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFAJY1XY5T wig3Ge+YRAvW1AJ 9GtZQ3MGpcqakdY m47lATJFxXt5gCf agzO
gLzOe3nZGsufv+r ITFeMnec=
=Zgto
-----END PGP SIGNATURE-----

Nov 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2317
by: lawrence | last post by:
I'm probably missing something obvious, but I'm unable to write a file with this function. I've used my FTP software to set permissions to 777 on all the files in question. I've tried r, r+, w, and w+ as possible ways of opening the files. The first fopen is trying to create a file where none exists. It fails (thought I've set dir...
3
6959
by: Evangelista Sami | last post by:
hello i have this strange error message that i dont understand : _search.c: In function `_depth_search': _search.c:218: unable to find a register to spill in class `AREG' _search.c:218: this is the insn: (insn 83 82 84 (parallel ) (reg:SI 1 edx ))) (set (reg:SI 1 edx )
2
1937
by: genc_ymeri | last post by:
Hi, We are a team of 4 using win2003 server (sp1) in our dev machines and VS2003 for our .Net web app. We did make a copy of our project (located to one "hardwarely old" PC ) to our machines. All of us are getting the above error in ths subject. Everything works fine in the original machine. (project name is not the same neither include the...
4
4823
by: Miguel Dias Moura | last post by:
Hello, I created a datalist in an ASP.Net / VB page. I display the image and price of a few products. When a user clicks an image I want to load the page "detail.aspx?number=id" and send the value of the "id" field of that record as a URL parameter. Can someone tell me how to do this.
6
10595
by: Stan Cook | last post by:
I'm writing a script to list all of my music files' id3 tags to a comma delimited file. The only part I'm missing seems like it should be the simplest. I haven't used Python for the last couple of years. My question is this: When I use os.open(<file_variable>,"w"), I get an error message, TypeError: an integer is required. Has...
5
5881
by: Henrik | last post by:
The problem is (using MS Access 2003) I am unable to retrieve long strings (255 chars) from calculated fields through a recordset. The data takes the trip in three phases: 1. A custom public function returns a long string. This works. 2. A query has a calculated field based on the custom function above. This works when the query is run...
15
2670
by: harvey | last post by:
How do I make PHP create a database for mysql please? I can see how to make tables and I have read all the documents I can find but I don't understand how to make the database itself. All the tutorials I can find seem to bypass the issue by ignoring it? Am I missunderstanding something?
19
6868
by: loudking | last post by:
Hello, all My manager told me to create a large file of 2GB The first 1GB is filled with "Hello" and the secod 1GB is filled with "World" Sorry to say that I don't know how to do that in an elegant way.
3
2396
by: ashishc | last post by:
Hi All, I have written a AutoSuggest in jsp and am using javascript to call the strut page which calls the database and returns me the xml back. On the html page i have a text box where i enter the name of the city and I have a DIV tag which I populate with the results. Now my problem is that, after I get the results back I am not able to...
0
7843
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7967
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.