pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Can functions return NULL value?
7+ messages / 3 participants
[nested] [flat]

* Can functions return NULL value?
@ 2000-05-08 21:07 Andrea Austa <aausta@athena.polito.it>
  2000-05-08 23:37 ` Re: Can functions return NULL value? Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 7+ messages in thread

From: Andrea Austa @ 2000-05-08 21:07 UTC (permalink / raw)
  To: pgsql-interfaces

Can a function, written in C, return a NULL value?
I would like write code like this:

	text * getnull (text * t)
	{
		return NULL;
	}

but it doesn't work, the backend terminates abnormally.

Thanks a lot


-- 
                 Andrea Austa - aausta@athena.polito.it
                         Debian GNU/Linux User
--



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

* Re: Can functions return NULL value?
  2000-05-08 21:07 Can functions return NULL value? Andrea Austa <aausta@athena.polito.it>
@ 2000-05-08 23:37 ` Tom Lane <tgl@sss.pgh.pa.us>
  2000-05-09 11:54   ` Re: Can functions return NULL value? Hannu Krosing <hannu@tm.ee>
  0 siblings, 1 reply; 7+ messages in thread

From: Tom Lane @ 2000-05-08 23:37 UTC (permalink / raw)
  To: Andrea Austa <aausta@athena.polito.it>; +Cc: pgsql-interfaces

Andrea Austa <aausta@athena.polito.it> writes:
> Can a function, written in C, return a NULL value?
> I would like write code like this:

> 	text * getnull (text * t)
> 	{
> 		return NULL;
> 	}

> but it doesn't work, the backend terminates abnormally.

This will be possible in 7.1 with the new function manager interface.
Right now, it's not possible.



(If your stomach is easily turned, stop reading here.)



There is an incredibly ugly hack for single-argument functions;
if that's the only kind you need to do this for, you're in luck.
A single-argument function implicitly gets a second "bool *"
argument, which on entry tells you whether the argument is NULL,
and on exit tells whether the result is NULL.  So:

    text * getnull (text * t, bool * isNull)
    {
        if (*isNull)
        {
            /* passed argument is NULL, do appropriate thing */
        }
        else
        {
            /* normal case here */
        }
        if (want-to-return-NULL)
        {
            *isNull = true;
            return NULL;
        }
        else
        {
            *isNull = false;  /* necessary iff arg is NULL */
            return appropriate-value;
        }
    }

Note that you still declare the function to SQL as taking a single
argument; the extra arg only appears at the C level.

This was only meant to support implementation of IS NULL/IS NOT NULL,
which is why it only copes with the single-argument case.  7.1 will
replace this crock with a more reasonable design that passes in a
separate isNull flag for each argument, and also has an isNull flag
the function can set for its result value.  See past discussions of
function manager redesign in pghackers archives (last thread was
in late Oct 99).

			regards, tom lane



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

* Re: Can functions return NULL value?
  2000-05-08 21:07 Can functions return NULL value? Andrea Austa <aausta@athena.polito.it>
  2000-05-08 23:37 ` Re: Can functions return NULL value? Tom Lane <tgl@sss.pgh.pa.us>
@ 2000-05-09 11:54   ` Hannu Krosing <hannu@tm.ee>
  2000-05-09 13:50     ` Re: Can functions return NULL value? Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 7+ messages in thread

From: Hannu Krosing @ 2000-05-09 11:54 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Andrea Austa <aausta@athena.polito.it>; pgsql-interfaces

Tom Lane wrote:
> 
> Andrea Austa <aausta@athena.polito.it> writes:
> > Can a function, written in C, return a NULL value?
> > I would like write code like this:
> 
> >       text * getnull (text * t)
> >       {
> >               return NULL;
> >       }
> 
> > but it doesn't work, the backend terminates abnormally.
> 
> This will be possible in 7.1 with the new function manager interface.
> Right now, it's not possible.

Who is doing the new function manager interface.

Is there a preliminary description somewhere ?

What is the planned timetable?

I ask because friend of mine is working on plpython (and has the 
basics working) on current code but he is quite turned off by the 
ugliness of current function manager (and SPI interface). 

----------------
Hannu



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

* Re: Can functions return NULL value?
  2000-05-08 21:07 Can functions return NULL value? Andrea Austa <aausta@athena.polito.it>
  2000-05-08 23:37 ` Re: Can functions return NULL value? Tom Lane <tgl@sss.pgh.pa.us>
  2000-05-09 11:54   ` Re: Can functions return NULL value? Hannu Krosing <hannu@tm.ee>
@ 2000-05-09 13:50     ` Tom Lane <tgl@sss.pgh.pa.us>
  2000-05-09 16:42       ` Re: Can functions return NULL value? Hannu Krosing <hannu@tm.ee>
  0 siblings, 1 reply; 7+ messages in thread

From: Tom Lane @ 2000-05-09 13:50 UTC (permalink / raw)
  To: Hannu Krosing <hannu@tm.ee>; +Cc: Andrea Austa <aausta@athena.polito.it>; pgsql-interfaces

Hannu Krosing <hannu@tm.ee> writes:
>> This will be possible in 7.1 with the new function manager interface.
>> Right now, it's not possible.

> Who is doing the new function manager interface.

Me.

> Is there a preliminary description somewhere ?

I posted a proposal to pghackers around 20 Oct last year; it's changed a
little since then but not much.

> What is the planned timetable?

7.1.  I have fmgr.c code that compiles (as of late last night) but
probably still has bugs.  I haven't started on converting any individual
functions, nor have I touched the PLfoo modules yet.

> I ask because friend of mine is working on plpython (and has the 
> basics working) on current code but he is quite turned off by the 
> ugliness of current function manager (and SPI interface). 

Wasn't planning to touch the SPI interface in this go-round, but if
someone else wants to...

			regards, tom lane



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

* Re: Can functions return NULL value?
  2000-05-08 21:07 Can functions return NULL value? Andrea Austa <aausta@athena.polito.it>
  2000-05-08 23:37 ` Re: Can functions return NULL value? Tom Lane <tgl@sss.pgh.pa.us>
  2000-05-09 11:54   ` Re: Can functions return NULL value? Hannu Krosing <hannu@tm.ee>
  2000-05-09 13:50     ` Re: Can functions return NULL value? Tom Lane <tgl@sss.pgh.pa.us>
@ 2000-05-09 16:42       ` Hannu Krosing <hannu@tm.ee>
  2000-05-09 17:42         ` Re: Can functions return NULL value? Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 7+ messages in thread

From: Hannu Krosing @ 2000-05-09 16:42 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-interfaces

Tom Lane wrote:
> 
> Hannu Krosing <hannu@tm.ee> writes:
> >> This will be possible in 7.1 with the new function manager interface.
> >> Right now, it's not possible.
> 
> > Who is doing the new function manager interface.
> 
> Me.
> 
> > Is there a preliminary description somewhere ?
> 
> I posted a proposal to pghackers around 20 Oct last year; it's changed a
> little since then but not much.

Ok, ill' find it.

> > What is the planned timetable?
> 
> 7.1.  I have fmgr.c code that compiles (as of late last night) but
> probably still has bugs.  I haven't started on converting any individual
> functions, nor have I touched the PLfoo modules yet.

When will it be available to the general public (i.e. me ;) ?

---------------
Hannu



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

* Re: Can functions return NULL value?
  2000-05-08 21:07 Can functions return NULL value? Andrea Austa <aausta@athena.polito.it>
  2000-05-08 23:37 ` Re: Can functions return NULL value? Tom Lane <tgl@sss.pgh.pa.us>
  2000-05-09 11:54   ` Re: Can functions return NULL value? Hannu Krosing <hannu@tm.ee>
  2000-05-09 13:50     ` Re: Can functions return NULL value? Tom Lane <tgl@sss.pgh.pa.us>
  2000-05-09 16:42       ` Re: Can functions return NULL value? Hannu Krosing <hannu@tm.ee>
@ 2000-05-09 17:42         ` Tom Lane <tgl@sss.pgh.pa.us>
  2000-05-09 16:52           ` Re: Can functions return NULL value? Hannu Krosing <hannu@tm.ee>
  0 siblings, 1 reply; 7+ messages in thread

From: Tom Lane @ 2000-05-09 17:42 UTC (permalink / raw)
  To: Hannu Krosing <hannu@tm.ee>; +Cc: pgsql-interfaces

Hannu Krosing <hannu@tm.ee> writes:
>>>> What is the planned timetable?
>> 
>> 7.1.  I have fmgr.c code that compiles (as of late last night) but
>> probably still has bugs.  I haven't started on converting any individual
>> functions, nor have I touched the PLfoo modules yet.

> When will it be available to the general public (i.e. me ;) ?

I'm planning to commit what I have as soon as Marc makes the CVS branch
for 7.1.  Sounds like that'll be around the end of the month.

			regards, tom lane



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

* Re: Can functions return NULL value?
  2000-05-08 21:07 Can functions return NULL value? Andrea Austa <aausta@athena.polito.it>
  2000-05-08 23:37 ` Re: Can functions return NULL value? Tom Lane <tgl@sss.pgh.pa.us>
  2000-05-09 11:54   ` Re: Can functions return NULL value? Hannu Krosing <hannu@tm.ee>
  2000-05-09 13:50     ` Re: Can functions return NULL value? Tom Lane <tgl@sss.pgh.pa.us>
  2000-05-09 16:42       ` Re: Can functions return NULL value? Hannu Krosing <hannu@tm.ee>
  2000-05-09 17:42         ` Re: Can functions return NULL value? Tom Lane <tgl@sss.pgh.pa.us>
@ 2000-05-09 16:52           ` Hannu Krosing <hannu@tm.ee>
  0 siblings, 0 replies; 7+ messages in thread

From: Hannu Krosing @ 2000-05-09 16:52 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-interfaces

Tom Lane wrote:
> 
> Hannu Krosing <hannu@tm.ee> writes:
> >>>> What is the planned timetable?
> >>
> >> 7.1.  I have fmgr.c code that compiles (as of late last night) but
> >> probably still has bugs.  I haven't started on converting any individual
> >> functions, nor have I touched the PLfoo modules yet.
> 
> > When will it be available to the general public (i.e. me ;) ?
> 
> I'm planning to commit what I have as soon as Marc makes the CVS branch
> for 7.1.  Sounds like that'll be around the end of the month.

What will people do the remaining tree weeks ?

A well deserved rest perhaps ;)

---------------
Hannu



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


end of thread, other threads:[~2000-05-09 17:42 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-05-08 21:07 Can functions return NULL value? Andrea Austa <aausta@athena.polito.it>
2000-05-08 23:37 ` Tom Lane <tgl@sss.pgh.pa.us>
2000-05-09 11:54   ` Hannu Krosing <hannu@tm.ee>
2000-05-09 13:50     ` Tom Lane <tgl@sss.pgh.pa.us>
2000-05-09 16:42       ` Hannu Krosing <hannu@tm.ee>
2000-05-09 17:42         ` Tom Lane <tgl@sss.pgh.pa.us>
2000-05-09 16:52           ` Hannu Krosing <hannu@tm.ee>

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