Обсуждение: referencing an attribute of a ROWTYPE variable in pgpsql using quote_ident or quote_literal
referencing an attribute of a ROWTYPE variable in pgpsql using quote_ident or quote_literal
От
"David Monarchi"
Дата:
Hello -
I'm using PG 8.2. I have the following code snippet:
The error message I receive is
I'm trying to dynamically assign values to attributes in a record without know which attribute values I will actually receive. I will always receive at least two key-value pairs with the elements separated by tabs.
I have tried both quote_literal and quote_ident with the same result. Any advice or suggestions would be much appreciated.
Thank you.
David
I'm using PG 8.2. I have the following code snippet:
adServerLoadRow domain2_dom%ROWTYPE;
attName text;
line text;
i int;
attName text;
line text;
i int;
i = 3;
attName := split_part(line,E'\t',i);
adServerLoadRow.quote_literal(attName) = split_part(line,'\t',i+1);
attName := split_part(line,E'\t',i);
adServerLoadRow.quote_literal(attName) = split_part(line,'\t',i+1);
The error message I receive is
ERROR: row "adserverloadrow" has no field "quote_literal"
SQL state: 42703
Context: compile of PL/pgSQL function "adserverfunctionbody" near line 57
SQL state: 42703
Context: compile of PL/pgSQL function "adserverfunctionbody" near line 57
I'm trying to dynamically assign values to attributes in a record without know which attribute values I will actually receive. I will always receive at least two key-value pairs with the elements separated by tabs.
I have tried both quote_literal and quote_ident with the same result. Any advice or suggestions would be much appreciated.
Thank you.
David
"David Monarchi" <david.e.monarchi@gmail.com> writes: > I'm trying to dynamically assign values to attributes in a record without > know which attribute values I will actually receive. You're wasting your time trying to do that in plpgsql --- quite aside from syntactic difficulties, the language doesn't work well for this because it's statically typed. Use one of the other PL languages. In plperl, for instance, a record looks like a hash and it's easy to iterate through the keys etc. regards, tom lane