pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feednon-cachable 'C' language functions
2+ messages / 2 participants
[nested] [flat]
* non-cachable 'C' language functions
@ 2000-08-12 01:18 Forest Wilkinson <fspam@home.com>
0 siblings, 1 reply; 2+ messages in thread
From: Forest Wilkinson @ 2000-08-12 01:18 UTC (permalink / raw)
To: pgsql-sql
(using postgresql 6.5.2)
I have created a set of postgres extension functions in C (which use SPI
to perform queries), and added them to my database with something like
this:
CREATE FUNCTION my_next_uid(text) RETURNS text AS
'/usr/lib/pgsql/my_uids.so' LANGUAGE 'c';
My functions are designed to behave like nextval() and friends, except
that they operate on a varchar field in a predetermined table, rather than
a database sequence. For example, my_next_uid() should always return a
unique value, incrementing the current value in said table each time it is
called.
So far, my functions appear to work correctly. However, looking at their
entries in the pg_proc table, I see that their "proiscachable" fields are
set to true. This worries me, because my understanding is that postgres
will re-use values returned by cachable functions, which is undesirable.
(In order for my_next_uid() to be useful, it must retrieve a new value
each time it is used.)
Is my understanding correct? What should I do about it? The postgresql
6.5.2 docs for CREATE FUNCTION don't tell me how to make my functions
non-cachable.
Regards,
Forest Wilkinson
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: non-cachable 'C' language functions
@ 2000-08-12 01:32 Tom Lane <tgl@sss.pgh.pa.us>
parent: Forest Wilkinson <fspam@home.com>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2000-08-12 01:32 UTC (permalink / raw)
To: Forest Wilkinson <fspam@home.com>; +Cc: pgsql-sql
Forest Wilkinson <fspam@home.com> writes:
> Is my understanding correct? What should I do about it? The postgresql
> 6.5.2 docs for CREATE FUNCTION don't tell me how to make my functions
> non-cachable.
6.5 doesn't pay any attention to proiscachable, AFAIR. 7.0 does, but
it defaults to assuming proiscachable = FALSE; you have to say
"with (iscachable)" in CREATE FUNCTION to get the other behavior.
There is a problem in both versions that WHERE clauses containing
no variables (table fields) will be assumed to be constants even
if they contain non-cachable function calls :-(. Thus, for example,
select * from foo where random() < 0.5
doesn't work as desired. I plan to fix this for 7.1.
Offhand I don't see a use for a nextval-like function in WHERE,
so you're probably safe with both 6.5 and 7.0.
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2000-08-12 01:32 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-08-12 01:18 non-cachable 'C' language functions Forest Wilkinson <fspam@home.com>
2000-08-12 01:32 ` Tom Lane <tgl@sss.pgh.pa.us>
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