pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Question about SQL FUnction
2+ messages / 2 participants
[nested] [flat]

* Question about SQL FUnction
@ 1999-02-17 19:03  Martin Möderndorfer <mmoedern@linux.stuco.uni-klu.ac.at>
  0 siblings, 1 reply; 2+ messages in thread

From: Martin Möderndorfer @ 1999-02-17 19:03 UTC (permalink / raw)
  To: pgsql-sql

hi,

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.

is it possible (and how ;-) to write such a very _flexible_ function??

MArtin



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

* Re: [SQL] Question about SQL FUnction
@ 1999-02-18 00:52  David Martinez Cuevas <david@estadistica.unam.mx>
  parent: Martin Möderndorfer <mmoedern@linux.stuco.uni-klu.ac.at>
  0 siblings, 0 replies; 2+ messages in thread

From: David Martinez Cuevas @ 1999-02-18 00:52 UTC (permalink / raw)
  To: Martin Möderndorfer <mmoedern@linux.stuco.uni-klu.ac.at>; +Cc: pgsql-sql


On Wed, 17 Feb 1999, Martin [iso-8859-1] Möderndorfer 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 "
                           @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@   





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


end of thread, other threads:[~1999-02-18 00:52 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-02-17 19:03 Question about SQL FUnction Martin Möderndorfer <mmoedern@linux.stuco.uni-klu.ac.at>
1999-02-18 00:52 ` David Martinez Cuevas <david@estadistica.unam.mx>

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