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. :-)
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 - select * from pg_language;
and post the results.
2) Post the function declaration, which you sourcing from an external file.
- select * from pg_language;
Here's the result for this step: -
lanname | lanispl | lanpltrusted | lanplcallfoid | lanvalidator | lanacl
-
----------+---------+--------------+---------------+--------------+---------------
-
internal | f | f | 0 | 2246 |
-
c | f | f | 0 | 2247 |
-
sql | f | t | 0 | 2248 | {=U/postgres}
-
(3 rows)
-
Here's the code of the function I was trying to compile. -
create or replace function upd_menu (varchar(50),real, varchar(50),varchar(100)) returns integer as
-
'
-
declare
-
foodname alias for $1;
-
foodprice alias for $2;
-
fname alias for $3;
-
fpath alias for $4;
-
check_validity integer;
-
id_photo integer;
-
-
begin
-
update food
-
set price = foodprice
-
where food = foodname;
-
-
id_photo:= ''select id from tbl_photo a, menu b where a.id = b.photo_id and food=foodname'';
-
if id_photo > 0 then
-
-
update tbl_photo
-
set filename = fname
-
, filepath = fpath
-
where id = id_photo;
-
-
select 1 as result;
-
else
-
insert into tbl_photo (id, filename,filepath) values (select get_highest_id()+1, fname, fpath);
-
select 1 as result;
-
end if;
-
-
-
end;
-
'
-
language plpgsql;
-
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: -
create or replace function upd_menu (varchar(50),real, varchar(50),varchar(100)) returns integer as
-
'
-
declare
-
foodname alias for $1;
-
foodprice alias for $2;
-
fname alias for $3;
-
fpath alias for $4;
-
check_validity integer;
-
id_photo integer;
-
-
begin
-
update menu
-
set price = foodprice
-
where food = foodname;
-
-
-- id_photo:= ''select id as id_photo from tbl_photo a, menu b where a.id = b.photo_id and food=foodname'';
-
select id as id_photo from tbl_photo a, menu b where a.id = b.photo_id and food=foodname;
-
if id_photo > 0 then
-
-
update tbl_photo
-
set filename = fname
-
, filepath = fpath
-
where id = id_photo;
-
-
return 1;
-
else
-
insert into tbl_photo (id, filename,filepath) values (select get_highest_id()+1, fname, fpath);
-
return 1;
-
end if;
-
-
-
end;
-
'
-
language 'plpgsql';
-
Here's what I executed: -
select upd_menu('hamburger', 90, 'hamburger','upload/hamburgertransparent2kb.gif');
-
Thanks for your help!
michaelb 534
Recognized Expert Contributor
Hi, twinklyblue;
The error message is indeed not very helpful, let's try to replace -
select id as id_photo from tbl_photo a, menu b ...
-
-- WITH
-
select id into id_photo from tbl_photo a, menu b ...
-
although I'm a bit surprised that this wasn't caught at compilation.
Let us know whether this helped.
HI Mike,
Sorry for the late reply but apparently, I was able to debug my script. Thanks for your help as always!
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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:
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |