Skip to content

Commit 88ba64d

Browse files
committed
Back out patch, wrong previous commit message.
1 parent b6477c6 commit 88ba64d

File tree

8 files changed

+38
-472
lines changed

8 files changed

+38
-472
lines changed

doc/src/sgml/plpgsql.sgml

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.91 2006/05/30 11:54:51 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.92 2006/05/30 11:58:05 momjian Exp $ -->
22

33
<chapter id="plpgsql">
44
<title><application>PL/pgSQL</application> - <acronym>SQL</acronym> Procedural Language</title>
@@ -879,55 +879,6 @@ SELECT merge_fields(t.*) FROM table1 t WHERE ... ;
879879
field in it will draw a run-time error.
880880
</para>
881881

882-
<para>
883-
To obtain the values of the fields the record is made up of,
884-
the record variable can be qualified with the column or field
885-
name. This can be done either by literally using the column name
886-
or the column name for indexing the record can be taken out of a scalar
887-
variable. The syntax for this notation is Record_variable.(IndexVariable).
888-
To get information about the column field names of the record,
889-
a special expression exists that returns all column names as an array:
890-
RecordVariable.(*) .
891-
Thus, the RECORD can be viewed
892-
as an associative array that allows for introspection of it's contents.
893-
This feature is especially useful for writing generic triggers that
894-
operate on records with unknown structure.
895-
Here is an example procedure that shows column names and values
896-
of the predefined record NEW in a trigger procedure:
897-
<programlisting>
898-
899-
CREATE OR REPLACE FUNCTION show_associative_records() RETURNS TRIGGER AS $$
900-
DECLARE
901-
colname TEXT;
902-
colcontent TEXT;
903-
colnames TEXT[];
904-
coln INT4;
905-
coli INT4;
906-
BEGIN
907-
-- obtain an array with all field names of the record
908-
colnames := NEW.(*);
909-
RAISE NOTICE 'All column names of test record: %', colnames;
910-
-- show field names and contents of record
911-
coli := 1;
912-
coln := array_upper(colnames,1);
913-
RAISE NOTICE 'Number of columns in NEW: %', coln;
914-
FOR coli IN 1 .. coln LOOP
915-
colname := colnames[coli];
916-
colcontent := NEW.(colname);
917-
RAISE NOTICE 'column % of NEW: %', quote_ident(colname), quote_literal(colcontent);
918-
END LOOP;
919-
-- Do it with a fixed field name:
920-
-- will have to know the column name
921-
RAISE NOTICE 'column someint of NEW: %', quote_literal(NEW.someint);
922-
RETURN NULL;
923-
END;
924-
$$ LANGUAGE plpgsql;
925-
--CREATE TABLE test_records (someint INT8, somestring TEXT);
926-
--CREATE TRIGGER tr_test_record BEFORE INSERT ON test_records FOR EACH ROW EXECUTE PROCEDURE show_associative_records();
927-
928-
</programlisting>
929-
</para>
930-
931882
<para>
932883
Note that <literal>RECORD</> is not a true data type, only a placeholder.
933884
One should also realize that when a <application>PL/pgSQL</application>

src/pl/plpgsql/src/pl_comp.c

Lines changed: 3 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.103 2006/05/30 11:54:51 momjian Exp $
11+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.104 2006/05/30 11:58:05 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -884,8 +884,7 @@ plpgsql_parse_dblword(char *word)
884884

885885
new = palloc(sizeof(PLpgSQL_recfield));
886886
new->dtype = PLPGSQL_DTYPE_RECFIELD;
887-
new->fieldindex.fieldname = pstrdup(cp[1]);
888-
new->fieldindex_flag = RECFIELD_USE_FIELDNAME;
887+
new->fieldname = pstrdup(cp[1]);
889888
new->recparentno = ns->itemno;
890889

891890
plpgsql_adddatum((PLpgSQL_datum *) new);
@@ -991,8 +990,7 @@ plpgsql_parse_tripword(char *word)
991990

992991
new = palloc(sizeof(PLpgSQL_recfield));
993992
new->dtype = PLPGSQL_DTYPE_RECFIELD;
994-
new->fieldindex.fieldname = pstrdup(cp[2]);
995-
new->fieldindex_flag = RECFIELD_USE_FIELDNAME;
993+
new->fieldname = pstrdup(cp[2]);
996994
new->recparentno = ns->itemno;
997995

998996
plpgsql_adddatum((PLpgSQL_datum *) new);
@@ -1440,132 +1438,6 @@ plpgsql_parse_dblwordrowtype(char *word)
14401438
return T_DTYPE;
14411439
}
14421440

1443-
/* ----------
1444-
* plpgsql_parse_recindex
1445-
* lookup associative index into record
1446-
* ----------
1447-
*/
1448-
int
1449-
plpgsql_parse_recindex(char *word)
1450-
{
1451-
PLpgSQL_nsitem *ns1, *ns2;
1452-
char *cp[2];
1453-
int ret = T_ERROR;
1454-
char *fieldvar;
1455-
int fl;
1456-
1457-
/* Do case conversion and word separation */
1458-
plpgsql_convert_ident(word, cp, 2);
1459-
Assert(cp[1] != NULL);
1460-
1461-
/* cleanup the "(identifier)" string to "identifier" */
1462-
fieldvar = cp[1];
1463-
Assert(*fieldvar == '(');
1464-
++fieldvar; /* get rid of ( */
1465-
1466-
fl = strlen(fieldvar);
1467-
Assert(fieldvar[fl-1] == ')');
1468-
fieldvar[fl-1] = 0; /* get rid of ) */
1469-
1470-
/*
1471-
* Lookup the first word
1472-
*/
1473-
ns1 = plpgsql_ns_lookup(cp[0], NULL);
1474-
if ( ns1 == NULL )
1475-
{
1476-
pfree(cp[0]);
1477-
pfree(cp[1]);
1478-
return T_ERROR;
1479-
}
1480-
1481-
ns2 = plpgsql_ns_lookup(fieldvar, NULL);
1482-
pfree(cp[0]);
1483-
pfree(cp[1]);
1484-
if ( ns2 == NULL ) /* name lookup failed */
1485-
return T_ERROR;
1486-
1487-
switch (ns1->itemtype)
1488-
{
1489-
case PLPGSQL_NSTYPE_REC:
1490-
{
1491-
/*
1492-
* First word is a record name, so second word must be an
1493-
* variable holding the field name in this record.
1494-
*/
1495-
if ( ns2->itemtype == PLPGSQL_NSTYPE_VAR ) {
1496-
PLpgSQL_recfield *new;
1497-
1498-
new = palloc(sizeof(PLpgSQL_recfield));
1499-
new->dtype = PLPGSQL_DTYPE_RECFIELD;
1500-
new->fieldindex.indexvar_no = ns2->itemno;
1501-
new->fieldindex_flag = RECFIELD_USE_INDEX_VAR;
1502-
new->recparentno = ns1->itemno;
1503-
1504-
plpgsql_adddatum((PLpgSQL_datum *) new);
1505-
1506-
plpgsql_yylval.scalar = (PLpgSQL_datum *) new;
1507-
ret = T_SCALAR;
1508-
}
1509-
break;
1510-
}
1511-
default:
1512-
break;
1513-
}
1514-
return ret;
1515-
}
1516-
1517-
1518-
/* ----------
1519-
* plpgsql_parse_recfieldnames
1520-
* create fieldnames of a record
1521-
* ----------
1522-
*/
1523-
int
1524-
plpgsql_parse_recfieldnames(char *word)
1525-
{
1526-
PLpgSQL_nsitem *ns1;
1527-
char *cp[2];
1528-
int ret = T_ERROR;
1529-
1530-
/* Do case conversion and word separation */
1531-
plpgsql_convert_ident(word, cp, 2);
1532-
1533-
/*
1534-
* Lookup the first word
1535-
*/
1536-
ns1 = plpgsql_ns_lookup(cp[0], NULL);
1537-
if ( ns1 == NULL )
1538-
{
1539-
pfree(cp[0]);
1540-
pfree(cp[1]);
1541-
return T_ERROR;
1542-
}
1543-
1544-
pfree(cp[0]);
1545-
pfree(cp[1]);
1546-
1547-
switch (ns1->itemtype)
1548-
{
1549-
case PLPGSQL_NSTYPE_REC:
1550-
{
1551-
PLpgSQL_recfieldproperties *new;
1552-
1553-
new = palloc(sizeof(PLpgSQL_recfieldproperties));
1554-
new->dtype = PLPGSQL_DTYPE_RECFIELDNAMES;
1555-
new->recparentno = ns1->itemno;
1556-
new->save_fieldnames = NULL;
1557-
plpgsql_adddatum((PLpgSQL_datum *) new);
1558-
plpgsql_yylval.scalar = (PLpgSQL_datum *) new;
1559-
ret = T_SCALAR; /* ??? */
1560-
break;
1561-
}
1562-
default:
1563-
break;
1564-
}
1565-
return ret;
1566-
}
1567-
1568-
15691441
/*
15701442
* plpgsql_build_variable - build a datum-array entry of a given
15711443
* datatype

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy