473,472 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Cannot compile plpgsql function

37 New Member
Hi team,

I'm new in Postgres and I tried creating a stored procedure which performs numerous update procedure. As I compiled it, I was given the following error:

psql:storedproc.sql:33: ERROR: language "plpgsql" does not exist
HINT: You need to use "createlang" to load the language into the database.

So I tried to execute this code but nothing was returned:

>createlang plpgsql workdb

Thinking that everything was okay (since no error or confirmation was returned), I begin to recompile my function.

workdb-# \i storeproc.sql
storeproc.sql: ¤½¤Î¤è¤¦¤Ê¥Õ¥¡¥¤¥ë¤ä¥Ç¥£¥ì¥¯¥È¥ê¤Ï¤¢¤ê¤Þ¤»¤ó

But was given that weird msgs. I am using a Japanese OS and I am not sure if this is related to it. To anyone who knows about this problem, your help would be greatly appreciated. :-)
Jun 13 '07 #1
6 5019
michaelb
534 Recognized Expert Contributor
I cannot decipher the error message, but there are two things you can do to help with debugging:

1) Run command createlang workdb -l
or even better, run this query
Expand|Select|Wrap|Line Numbers
  1. select * from pg_language;
and post the results.

2) Post the function declaration, which you sourcing from an external file.
Jun 14 '07 #2
twinklyblue
37 New Member
Expand|Select|Wrap|Line Numbers
  1. select * from pg_language;
Here's the result for this step:
Expand|Select|Wrap|Line Numbers
  1.  lanname  | lanispl | lanpltrusted | lanplcallfoid | lanvalidator |    lanacl   
  2. ----------+---------+--------------+---------------+--------------+---------------
  3.  internal | f       | f            |             0 |         2246 |
  4.  c        | f       | f            |             0 |         2247 |
  5.  sql      | f       | t            |             0 |         2248 | {=U/postgres}
  6. (3 rows)
  7.  
Here's the code of the function I was trying to compile.
Expand|Select|Wrap|Line Numbers
  1. create or replace function upd_menu (varchar(50),real, varchar(50),varchar(100)) returns integer as
  2. '
  3. declare
  4.        foodname alias for $1;
  5.        foodprice alias for $2;
  6.        fname alias for $3;
  7.        fpath alias for $4;
  8.        check_validity integer;
  9.        id_photo integer;
  10.  
  11. begin
  12.      update food 
  13.      set price = foodprice
  14.      where food = foodname;
  15.  
  16.      id_photo:= ''select id from tbl_photo a, menu b where a.id = b.photo_id and food=foodname'';
  17.      if id_photo > 0 then
  18.  
  19.         update tbl_photo
  20.         set filename = fname
  21.         , filepath = fpath
  22.         where id =  id_photo;
  23.  
  24.         select 1 as result;   
  25.      else
  26.          insert into tbl_photo (id, filename,filepath) values (select get_highest_id()+1, fname, fpath);
  27.          select 1 as result;
  28.      end if; 
  29.  
  30.  
  31. end;
  32. '
  33. language plpgsql;
  34.  
Jun 19 '07 #3
michaelb
534 Recognized Expert Contributor
As you can see there's no plpgsql language in your database.
The function definition may have its own issues, but you need to create the language first.

I am not sure what went wrong, did you ran this query on the same database where you tried to create language?
It may be helpful to review these man pages and try again.
If you succeed createlang -l or the query you ran should show plpgsql.

http://www.postgresql.org/docs/8.1/static/xplang.html
http://www.postgresql.org/docs/8.1/s...reatelang.html
http://www.postgresql.org/docs/8.1/s...elanguage.html
Jun 20 '07 #4
twinklyblue
37 New Member
As you can see there's no plpgsql language in your database.
The function definition may have its own issues, but you need to create the language first.

I am not sure what went wrong, did you ran this query on the same database where you tried to create language?
It may be helpful to review these man pages and try again.
If you succeed createlang -l or the query you ran should show plpgsql.

http://www.postgresql.org/docs/8.1/static/xplang.html
http://www.postgresql.org/docs/8.1/s...reatelang.html
http://www.postgresql.org/docs/8.1/s...elanguage.html

Hi Mike, The language apparently was installed by someone (i am not sure who but the last time i check it..it was already there) so I tried to recompile the stored proc again. It was successfully recompiled however, there is a runtime error which I cant understand. (postgreSQL's error display is really not that friendly, IMHO).

error:
ERROR: syntax error at or near "$1" at character 16
CONTEXT: PL/pgSQL function "upd_menu" line 15 at SQL statement


my script:

Expand|Select|Wrap|Line Numbers
  1. create or replace function upd_menu (varchar(50),real, varchar(50),varchar(100)) returns integer as
  2. '
  3. declare
  4.        foodname alias for $1;
  5.        foodprice alias for $2;
  6.        fname alias for $3;
  7.        fpath alias for $4;
  8.        check_validity integer;
  9.        id_photo integer;
  10.  
  11. begin
  12.      update menu 
  13.      set price = foodprice
  14.      where food = foodname;
  15.  
  16.    -- id_photo:= ''select id as id_photo from tbl_photo a, menu b where a.id = b.photo_id and food=foodname'';
  17.      select id as id_photo from tbl_photo a, menu b where a.id = b.photo_id and food=foodname;
  18.      if id_photo > 0 then
  19.  
  20.         update tbl_photo
  21.         set filename = fname
  22.         , filepath = fpath
  23.         where id =  id_photo;
  24.  
  25.         return 1;   
  26.      else
  27.          insert into tbl_photo (id, filename,filepath) values (select get_highest_id()+1, fname, fpath);
  28.         return 1;
  29.      end if; 
  30.  
  31.  
  32. end;
  33. '
  34. language 'plpgsql';
  35.  
Here's what I executed:

Expand|Select|Wrap|Line Numbers
  1. select upd_menu('hamburger', 90, 'hamburger','upload/hamburgertransparent2kb.gif'); 
  2.  
Thanks for your help!
Jun 21 '07 #5
michaelb
534 Recognized Expert Contributor
Hi, twinklyblue;

The error message is indeed not very helpful, let's try to replace
Expand|Select|Wrap|Line Numbers
  1. select id as id_photo from tbl_photo a, menu b ...
  2. -- WITH
  3. select id into id_photo from tbl_photo a, menu b ...
  4.  
although I'm a bit surprised that this wasn't caught at compilation.

Let us know whether this helped.
Jun 22 '07 #6
twinklyblue
37 New Member
HI Mike,

Sorry for the late reply but apparently, I was able to debug my script. Thanks for your help as always!
Jul 10 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Mark Mikulec | last post by:
Hi there, I wonder if anyone can shed some light on a very frustrating problem. I'm running a debian linux 3.0 "woody" server, nothing special, with the latest version of postres that apt-get...
5
by: Thomas LeBlanc | last post by:
I copied an example from the help: CREATE FUNCTION somefunc() RETURNS integer AS ' DECLARE quantity integer := 30; BEGIN RAISE NOTICE ''Quantity here is %'', quantity; -- Quantity here is 30...
6
by: Martin Marques | last post by:
We are trying to make some things work with plpgsql. The problem is that I built several functions that call one another, and I thought that the way of calling it was just making the assign: ...
10
by: lnd | last post by:
After copied pg database from one PC to another -I could not find plpgsql function(s) in the copied database. -had to instal plpgsql language handler again -whilst tables and data moved...
5
by: Thomas Chille | last post by:
Hi, i am playing around with PLpgSQL and can not solve one problem: I am fetching some rows of a special rowtype and wanna give this rows step by step to a function with this rowtype as...
14
by: Karl O. Pinc | last post by:
Hi, Thought perhaps some other eyes than mine can tell if I'm doing something wrong here or if there's a bug somewhere. I've never passed a ROWTYPE varaible to a function but I don't see where...
2
by: David Boone | last post by:
I've been trying to create functions with postgres, but it seems that queries run within a function take wayyy too long to complete. The increased time seems to be in the actual queries, not...
2
by: Mark Cave-Ayland | last post by:
Hi everyone, I'm trying to write a recursive plpgsql function in PostgreSQL 7.4.2 that given a tree node id (ictid) will return all the nodes below it in the tree, one row per node. When I try...
9
by: Karl O. Pinc | last post by:
I want to return multiple values, but not a set, only a single row, from a plpgsql function and I can't seem to get it to work. (I suppose I'd be happy to return a set, but I can't seem to make...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
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...
0
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...
0
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
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...

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.