pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ivo Simicevic <ivo@ultra.hr>
To: pgsql-interfaces@postgreSQL.org
Subject: Re: a couple of newbie question
Date: Sun, 16 Apr 2000 23:03:12 +0200
Message-ID: <20000416230312.A1117@ultra.hr> (raw)

On Sun, Apr 16, 2000 at 11:57:38AM -0700, Matthew Denny wrote:
> 
> I know this question is probably fairly elementary, but I could not
> find the answer in the docs or mailing list archives.  How does one handle
> NULL values in the embedded SQL interface?  For example, if I have a
> statement:
> 
> exec sql insert into test_table values(:foo, :x, :y)
> 
> and foo represents a CHAR attribute (represented by a string in C) that I
> want to set to NULL, how do I go about doing this?  

There are two ways :

  exec sql insert into test_table values (NULL,:x,:y)    or more properly

define indicator variable in DECLARE section and use it to insert null value
e.g.

  EXEC SQL BEGIN DECLARE SECTION;
  char foo[10];
  int x;
  int y;
  int indicator;
  EXEC SQL END DECLARE SECTION;
.....
  indicator=-1;
  EXEC SQL INSERT INTO test_table VALUES (:foo:indicator,:x,:y);


> Similarly, how do
> I tell that a value put into a variable by a fetch call is NULL or
> not?  
> 

  You can do it the same way:

  EXEC SQL SELECT foo,x,y
           INTO :foo:indicator,:x,:y
           ......

  and then check for indicator value.


GL

Ivo. 




view thread (3+ messages)

Message-ID: <20000416230312.A1117@ultra.hr>
Permalink:  ../20000416230312.A1117@ultra.hr/
Also on:    postgresql.org/message-id/20000416230312.A1117@ultra.hr

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: ivo@ultra.hr
  Subject: Re: a couple of newbie question
  In-Reply-To: <20000416230312.A1117@ultra.hr>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox