Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc24216b

Browse files
committed
Fix reverse FOR loop to work properly, uppercase cleanup in file.
1 parentec614c9 commitc24216b

File tree

1 file changed

+61
-56
lines changed

1 file changed

+61
-56
lines changed

‎doc/src/sgml/plsql.sgml

Lines changed: 61 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/Attic/plsql.sgml,v 2.42 2001/10/09 04:55:11 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/Attic/plsql.sgml,v 2.43 2001/10/12 21:19:09 momjian Exp $
33
-->
44

55
<chapter id="plpgsql">
@@ -228,8 +228,8 @@ END;
228228
when you reload the file, it'll drop your functions and then
229229
re-create them. For example:
230230
<programlisting>
231-
drop function testfunc(integer);
232-
create function testfunc(integer) returns integer as '
231+
DROP FUNCTION testfunc(integer);
232+
CREATE FUNCTION testfunc(INTEGER) RETURNS INTEGER AS '
233233
....
234234
end;
235235
' language 'plpgsql';
@@ -503,7 +503,7 @@ BEGIN
503503
user_id := users_rec.user_id;
504504
...
505505

506-
create function cs_refresh_one_mv(integer) returns integer as '
506+
CREATE FUNCTION cs_refresh_one_mv(INTEGER) RETURNS INTEGER AS '
507507
DECLARE
508508
key ALIAS FOR $1;
509509
table_data cs_materialized_views%ROWTYPE;
@@ -585,7 +585,7 @@ SELECT <replaceable>expression</replaceable>
585585
is a difference between what these two functions do:
586586

587587
<programlisting>
588-
CREATE FUNCTION logfunc1 (text) RETURNStimestamp AS '
588+
CREATE FUNCTION logfunc1 (TEXT) RETURNSTIMESTAMP AS '
589589
DECLARE
590590
logtxt ALIAS FOR $1;
591591
BEGIN
@@ -598,7 +598,7 @@ CREATE FUNCTION logfunc1 (text) RETURNS timestamp AS '
598598
and
599599

600600
<programlisting>
601-
CREATE FUNCTION logfunc2 (text) RETURNStimestamp AS '
601+
CREATE FUNCTION logfunc2 (TEXT) RETURNSTIMESTAMP AS '
602602
DECLARE
603603
logtxt ALIAS FOR $1;
604604
curtime timestamp;
@@ -793,7 +793,7 @@ DECLARE
793793
a_output varchar(4000);
794794
BEGIN
795795
a_output := ''CREATE FUNCTION cs_find_referrer_type(varchar,varchar,varchar)
796-
RETURNSvarchar AS ''''
796+
RETURNSVARCHAR AS ''''
797797
DECLARE
798798
v_host ALIAS FOR $1;
799799
v_domain ALIAS FOR $2;
@@ -1154,7 +1154,7 @@ FOR i IN 1..10 LOOP
11541154
RAISE NOTICE ''i is %'',i;
11551155
END LOOP;
11561156

1157-
FOR i IN REVERSE1..10 LOOP
1157+
FOR i IN REVERSE10..1 LOOP
11581158
-- some expressions here
11591159
END LOOP;
11601160
</programlisting>
@@ -1289,7 +1289,7 @@ END LOOP;
12891289

12901290
<para>
12911291
<programlisting>
1292-
create function cs_refresh_mviews () returnsinteger as '
1292+
create function cs_refresh_mviews () returnsINTEGER as '
12931293
DECLARE
12941294
mviews RECORD;
12951295

@@ -1642,7 +1642,7 @@ CREATE TRIGGER emp_stamp BEFORE INSERT OR UPDATE ON emp
16421642
</para>
16431643

16441644
<programlisting>
1645-
CREATE FUNCTION add_one (integer) RETURNSinteger AS '
1645+
CREATE FUNCTION add_one (integer) RETURNSINTEGER AS '
16461646
BEGIN
16471647
RETURN $1 + 1;
16481648
END;
@@ -1659,7 +1659,7 @@ CREATE FUNCTION add_one (integer) RETURNS integer AS '
16591659
</para>
16601660

16611661
<programlisting>
1662-
CREATE FUNCTION concat_text (text, text) RETURNStext AS '
1662+
CREATE FUNCTION concat_text (TEXT, TEXT) RETURNSTEXT AS '
16631663
BEGIN
16641664
RETURN $1 || $2;
16651665
END;
@@ -1682,7 +1682,7 @@ CREATE FUNCTION concat_text (text, text) RETURNS text AS '
16821682
</para>
16831683

16841684
<programlisting>
1685-
CREATE FUNCTION c_overpaid (EMP,integer) RETURNSboolean AS '
1685+
CREATE FUNCTION c_overpaid (EMP,INTEGER) RETURNSBOOLEAN AS '
16861686
DECLARE
16871687
emprec ALIAS FOR $1;
16881688
sallim ALIAS FOR $2;
@@ -1999,9 +1999,9 @@ SHOW ERRORS;
19991999
PostgreSQL:
20002000

20012001
<programlisting>
2002-
DROP FUNCTION cs_fmt_browser_version(varchar, varchar);
2003-
CREATE FUNCTION cs_fmt_browser_version(varchar, varchar)
2004-
RETURNSvarchar AS '
2002+
DROP FUNCTION cs_fmt_browser_version(VARCHAR, VARCHAR);
2003+
CREATE FUNCTION cs_fmt_browser_version(VARCHAR, VARCHAR)
2004+
RETURNSVARCHAR AS '
20052005
DECLARE
20062006
v_name ALIAS FOR $1;
20072007
v_version ALIAS FOR $2;
@@ -2058,13 +2058,13 @@ show errors
20582058
Here is how this function would end up in PostgreSQL:
20592059

20602060
<programlisting>
2061-
CREATE FUNCTION cs_update_referrer_type_proc() RETURNSinteger AS '
2061+
CREATE FUNCTION cs_update_referrer_type_proc() RETURNSINTEGER AS '
20622062
DECLARE
20632063
referrer_keys RECORD; -- Declare a generic record to be used in a FOR
20642064
a_output varchar(4000);
20652065
BEGIN
2066-
a_output := ''CREATE FUNCTION cs_find_referrer_type(varchar,varchar,varchar)
2067-
RETURNSvarchar AS ''''
2066+
a_output := ''CREATE FUNCTION cs_find_referrer_type(VARCHAR,VARCHAR,VARCHAR)
2067+
RETURNSVARCHAR AS ''''
20682068
DECLARE
20692069
v_host ALIAS FOR $1;
20702070
v_domain ALIAS FOR $2;
@@ -2152,8 +2152,8 @@ show errors;
21522152
Here is how this procedure could be translated for PostgreSQL:
21532153

21542154
<programlisting>
2155-
drop function cs_parse_url_host(varchar);
2156-
create function cs_parse_url_host(varchar) returns varchar as '
2155+
drop function cs_parse_url_host(VARCHAR);
2156+
create function cs_parse_url_host(VARCHAR) RETURNS VARCHAR AS '
21572157
declare
21582158
v_url ALIAS FOR $1;
21592159
v_host varchar;
@@ -2282,36 +2282,41 @@ show errors
22822282
So let's see one of the ways we could port this procedure to <application>PL/pgSQL</>:
22832283

22842284
<programlisting>
2285-
drop function cs_create_job(integer);
2286-
create function cs_create_job(integer) returns integer as 'declare
2287-
v_job_idalias for $1;
2288-
a_running_job_countinteger;
2285+
drop function cs_create_job(INTEGER);
2286+
create function cs_create_job(INTEGER) RETURNS INTEGER AS 'DECLARE
2287+
v_job_idALIAS FOR $1;
2288+
a_running_job_countINTEGER;
22892289
a_num integer;
22902290
-- pragma autonomous_transaction;
2291-
begin
2292-
lock table cs_jobs in exclusive mode;
2293-
select count(*) into a_running_job_count from cs_jobs where end_stamp is null;
2294-
2295-
if a_running_job_count > 0 then
2296-
-- commit; -- free lock
2297-
raise exception ''Unable to create a new job: a job is currently running.'';
2298-
end if;
2291+
BEGIN
2292+
LOCK TABLE cs_jobs IN EXCLUSIVE MODE;
2293+
SELECT count(*) INTO a_running_job_count
2294+
FROM cs_jobs
2295+
WHERE end_stamp IS NULL;
2296+
2297+
IF a_running_job_count > 0
2298+
THEN
2299+
-- COMMIT; -- free lock
2300+
RAISE EXCEPTION ''Unable to create a new job: a job is currently running.'';
2301+
END IF;
22992302

2300-
delete from cs_active_job;
2301-
insert into cs_active_job(job_id)values(v_job_id);
2303+
DELETE FROM cs_active_job;
2304+
INSERT INTO cs_active_job(job_id)VALUES(v_job_id);
23022305

2303-
SELECT count(*) into a_num FROM cs_jobs WHERE job_id=v_job_id;
2306+
SELECT count(*) into a_num
2307+
FROM cs_jobs
2308+
WHERE job_id=v_job_id;
23042309
IF NOT FOUND THEN -- If nothing was returned in the last query
23052310
-- This job is not in the table so lets insert it.
2306-
insert into cs_jobs(job_id, start_stamp)values(v_job_id, sysdate());
2307-
return 1;
2311+
INSERT INTO cs_jobs(job_id, start_stamp)VALUES(v_job_id, sysdate());
2312+
RETURN 1;
23082313
ELSE
2309-
raise NOTICE ''Job already running.'';<co id="co.plpgsql-porting-raise">
2314+
RAISE NOTICE ''Job already running.'';<co id="co.plpgsql-porting-raise">
23102315
END IF;
23112316

2312-
return 0;
2313-
end;
2314-
'language 'plpgsql';
2317+
RETURN 0;
2318+
END;
2319+
'LANGUAGE 'plpgsql';
23152320
</programlisting>
23162321

23172322
<calloutlist>
@@ -2382,8 +2387,8 @@ show errors
23822387
package would become something like this:
23832388

23842389
<programlisting>
2385-
CREATE FUNCTION acs__add_user(integer,integer,varchar,datetime,integer,integer,...)
2386-
RETURNSinteger AS '
2390+
CREATE FUNCTION acs__add_user(INTEGER,INTEGER,VARCHAR,DATETIME,INTEGER,INTEGER,...)
2391+
RETURNSINTEGER AS '
23872392
DECLARE
23882393
user_id ALIAS FOR $1;
23892394
object_type ALIAS FOR $2;
@@ -2397,7 +2402,7 @@ BEGIN
23972402
v_user_id := acs_user__new(user_id,object_type,creation_date,creation_user,creation_ip, ...);
23982403
...
23992404

2400-
return v_user_id;
2405+
RETURN v_user_id;
24012406
END;
24022407
' LANGUAGE 'plpgsql';
24032408
</programlisting>
@@ -2441,7 +2446,7 @@ END;
24412446
FUNCTION</command> statement. Something like:
24422447

24432448
<programlisting>
2444-
CREATE FUNCTION foo(...) RETURNSinteger AS '
2449+
CREATE FUNCTION foo(...) RETURNSINTEGER AS '
24452450
...
24462451
' LANGUAGE 'plpgsql'
24472452
WITH (isstrict, iscachable);
@@ -2479,7 +2484,7 @@ WITH (isstrict, iscachable);
24792484
--
24802485

24812486
DROP FUNCTION instr(varchar,varchar);
2482-
CREATE FUNCTION instr(varchar,varchar) RETURNSinteger AS '
2487+
CREATE FUNCTION instr(VARCHAR,VARCHAR) RETURNSINTEGER AS '
24832488
DECLARE
24842489
pos integer;
24852490
BEGIN
@@ -2489,8 +2494,8 @@ END;
24892494
' language 'plpgsql';
24902495

24912496

2492-
DROP FUNCTION instr(varchar,varchar,integer);
2493-
CREATE FUNCTION instr(varchar,varchar,integer) RETURNSinteger AS '
2497+
DROP FUNCTION instr(VARCHAR,VARCHAR,INTEGER);
2498+
CREATE FUNCTION instr(VARCHAR,VARCHAR,INTEGER) RETURNSINTEGER AS '
24942499
DECLARE
24952500
string ALIAS FOR $1;
24962501
string_to_search ALIAS FOR $2;
@@ -2536,20 +2541,20 @@ END;
25362541
-- Written by Robert Gaszewski (graszew@poland.com)
25372542
-- Licensed under the GPL v2 or later.
25382543
--
2539-
DROP FUNCTION instr(varchar,varchar,integer,integer);
2540-
CREATE FUNCTION instr(varchar,varchar,integer,integer) RETURNSinteger AS '
2544+
DROP FUNCTION instr(VARCHAR,VARCHAR,INTEGER,INTEGER);
2545+
CREATE FUNCTION instr(VARCHAR,VARCHAR,INTEGER,INTEGER) RETURNSINTEGER AS '
25412546
DECLARE
25422547
string ALIAS FOR $1;
25432548
string_to_search ALIAS FOR $2;
25442549
beg_index ALIAS FOR $3;
25452550
occur_index ALIAS FOR $4;
25462551
pos integer NOT NULL DEFAULT 0;
25472552
occur_number integer NOT NULL DEFAULT 0;
2548-
temp_strvarchar;
2549-
beginteger;
2550-
iinteger;
2551-
lengthinteger;
2552-
ss_lengthinteger;
2553+
temp_strVARCHAR;
2554+
begINTEGER;
2555+
iINTEGER;
2556+
lengthINTEGER;
2557+
ss_lengthINTEGER;
25532558
BEGIN
25542559
IF beg_index > 0 THEN
25552560
beg := beg_index;
@@ -2595,7 +2600,7 @@ BEGIN
25952600
RETURN 0;
25962601
END IF;
25972602
END;
2598-
'language 'plpgsql';
2603+
'LANGUAGE 'plpgsql';
25992604
</programlisting>
26002605
</sect3>
26012606
</sect2>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp