pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
a couple of newbie question
3+ messages / 3 participants
[nested] [flat]

* a couple of newbie question
@ 2000-04-16 18:57 Matthew Denny <mdenny@CS.Berkeley.EDU>
  2000-04-16 19:17 ` Re: [NOVICE] a couple of newbie question D. Duccini <duccini@backpack.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Matthew Denny @ 2000-04-16 18:57 UTC (permalink / raw)
  To: pgsql-interfaces; pgsql-novice@postgresql.org


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?  Similarly, how do
I tell that a value put into a variable by a fetch call is NULL or
not?  

On a different note, is there any list of error codes for the actual
postgreSQL errors, or is the only thing a user can get back is the
text message in sqlca.sqlerrm.sqlerrmc (e.g. no associated error #)?

Any help would be greatly appreciated.

thanks,
Matt



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [NOVICE] a couple of newbie question
  2000-04-16 18:57 a couple of newbie question Matthew Denny <mdenny@CS.Berkeley.EDU>
@ 2000-04-16 19:17 ` D. Duccini <duccini@backpack.com>
  0 siblings, 0 replies; 3+ messages in thread

From: D. Duccini @ 2000-04-16 19:17 UTC (permalink / raw)
  To: Matthew Denny <mdenny@CS.Berkeley.EDU>; +Cc: pgsql-interfaces; pgsql-novice@postgresql.org


You insert it by NOT inserting it.

insert into test_table (col_x, col_y) values (:x, :y);

you basically omit any column you do not want to insert values for

-duck

On Sun, 16 Apr 2000, 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?  Similarly, how do
> I tell that a value put into a variable by a fetch call is NULL or
> not?  
> 
> On a different note, is there any list of error codes for the actual
> postgreSQL errors, or is the only thing a user can get back is the
> text message in sqlca.sqlerrm.sqlerrmc (e.g. no associated error #)?
> 
> Any help would be greatly appreciated.
> 
> thanks,
> Matt
> 


-----------------------------------------------------------------------------
david@backpack.com            BackPack Software, Inc.        www.backpack.com
+1 651.645.7550 voice       "Life is an Adventure.    
+1 651.645.9798 fax            Don't forget your BackPack!"   
-----------------------------------------------------------------------------




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: a couple of newbie question
@ 2000-04-16 21:03 Ivo Simicevic <ivo@ultra.hr>
  0 siblings, 0 replies; 3+ messages in thread

From: Ivo Simicevic @ 2000-04-16 21:03 UTC (permalink / raw)
  To: pgsql-interfaces

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. 




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2000-04-16 21:03 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-04-16 18:57 a couple of newbie question Matthew Denny <mdenny@CS.Berkeley.EDU>
2000-04-16 19:17 ` D. Duccini <duccini@backpack.com>
2000-04-16 21:03 Re: a couple of newbie question Ivo Simicevic <ivo@ultra.hr>

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