assign null value to a field in plpgsql - Mailing list pgsql-novice

From David Monarchi
Subject assign null value to a field in plpgsql
Date
Msg-id eea51fdb0706011105u7c6216c2kecb3336659842085@mail.gmail.com
Whole thread Raw
Responses Re: assign null value to a field in plpgsql
List pgsql-novice
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

pgsql-novice by date:

Previous
From: Oliver Elphick
Date:
Subject: Re: STABLE has no effect on PL/pgsql functions
Next
From: Tom Lane
Date:
Subject: Re: assign null value to a field in plpgsql