Thread: assign null value to a field in plpgsql
Hello -
I'm using PG 8.2.
I have some code of the form
domain2Row domain2_dom%ROWTYPE;
adServerLoadRow domain2_dom%ROWTYPE;
...
SELECT * INTO domain2Row FROM domain2_dom WHERE domain_name_dom = quote_literal(domainName);
adServerLoadRow = domain2Row;
I want to go through a series of checks to see if I should set a field to null in the adServerLoadRow. I will not know in advance which fields I will need to check nor their data types.
Assuming I have identified field X as one which I want to set to null, I want to be able to perform the following assignment;
adServerLoadRow.X = NULL;
However, I can't seem to do this. I thought about just declaring a variable and not assigning anything to it, so it would be null. Then I could do the following
adServerLoadRow.X = aNullVariable;
The problem is that I won't know in advance whether the field is numeric or text, so I won't know which null variable to use.
I'm constrained to use plpgsql, so alternate language solutions won't help me.
Any suggestions would be greatly appreciated.
david
I'm using PG 8.2.
I have some code of the form
domain2Row domain2_dom%ROWTYPE;
adServerLoadRow domain2_dom%ROWTYPE;
...
SELECT * INTO domain2Row FROM domain2_dom WHERE domain_name_dom = quote_literal(domainName);
adServerLoadRow = domain2Row;
I want to go through a series of checks to see if I should set a field to null in the adServerLoadRow. I will not know in advance which fields I will need to check nor their data types.
Assuming I have identified field X as one which I want to set to null, I want to be able to perform the following assignment;
adServerLoadRow.X = NULL;
However, I can't seem to do this. I thought about just declaring a variable and not assigning anything to it, so it would be null. Then I could do the following
adServerLoadRow.X = aNullVariable;
The problem is that I won't know in advance whether the field is numeric or text, so I won't know which null variable to use.
I'm constrained to use plpgsql, so alternate language solutions won't help me.
Any suggestions would be greatly appreciated.
david
"David Monarchi" <david.e.monarchi@gmail.com> writes: > I want to go through a series of checks to see if I should set a field to > null in the adServerLoadRow. I will not know in advance which fields I will > need to check nor their data types. > ... > I'm constrained to use plpgsql, You've been given an impossible set of constraints, because plpgsql is a statically-typed language. Use another PL. regards, tom lane