From: | David Martinez Cuevas <david(at)estadistica(dot)unam(dot)mx> |
---|---|
To: | Martin Möderndorfer <mmoedern(at)linux(dot)stuco(dot)uni-klu(dot)ac(dot)at> |
Cc: | pgsql-sql(at)postgreSQL(dot)org |
Subject: | Re: [SQL] Question about SQL FUnction |
Date: | 1999-02-18 00:52:19 |
Message-ID: | Pine.LNX.4.04.9902171847350.31842-100000@mail.estadistica.unam.mx |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Wed, 17 Feb 1999, Martin [iso-8859-1] Mderndorfer wrote:
> hi,
Hi Martin
>
> i have some tables:
>
> create table person (nr int4, name varchar(50));
> create table book(nr int4, title varchar(50), persnr int4);
>
> (persnr is the foreign key -> person.nr)
>
> now i have some
> CREATE FUNCTION get_new_nr(**TABLE**,**FIELDS**) RETURNS int4;
> AS 'SELECT MAX($2) FROM $1 +1;'
> LANGUAGE 'sql';
>
> but **table** and **fields** needs some datatype. this function should
> return the max of a set of all numbers in person (+1) and return this.
Are you trying to get the MAX($2) in order to calculate the next value for
the primaryy key ????
If that's true, i would recommend you to use sequences
>
> is it possible (and how ;-) to write such a very _flexible_ function??
>
> MArtin
>
Functions written in sql are not very flexible... you just can't use the
arguments very well. It is better to write C functions with libpq.
Adios amigo.
David Martinez Cuevas
Office 622-60-80 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Home 565-25-17 "Eat Linux, Drink Linux... SMOKE LINUX "
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
From | Date | Subject | |
---|---|---|---|
Next Message | Anatoly K. Lasareff | 1999-02-18 07:37:50 | Re: [SQL] Question about SQL FUnction |
Previous Message | Peter Garner | 1999-02-18 00:46:14 | Re: [SQL] INSERT query (using insert from a Java application, concerning String input) |