Results 1 to 6 of 6

Thread: problem creating function

Threaded View

  1. #6
    Join Date
    Oct 2005
    Posts
    8

    example function in postgres

    The _really_ nice features of postgres functions require procedural languages to be installed. see
    http://www.postgresql.org/docs/8.0/i...ve/xplang.html for details. You also can download the docs and use it locally.
    if you setup the procedural language into your template1, all databases created afterwards will be able to use these languages.
    pl/pgsql is a quite simple one - but you have variables, conditionals and loops.

    an example of a very simple function written in this language would create a Customer ('kunde' in german) and a related mandant, setting the IDs making them joinable and return the auto-generated kndid (custumer-id).

    Code:
    create sequence mndidseq start 3100;
    create sequence kndidseq start 150;
    
    create or replace function "CreateKunde" (integer) returns integer as'
    	declare 
    		an Alias for $1;
    		nmid		integer;
    		nkid		integer;
    	begin	
    		nmid := nextval(''mndidseq'');
    		insert into "Mandant" ("MndID","Branche") values (nmid,''EDV'');
    		
    		nkid := nextval(''kndidseq'');
    		insert into "KundeVon" ("KndID","AufN","AufG") values (nkid,an,nmid);
    		return nkid;
    	end;'
    	language plpgsql;
    if you are used to ist, is very convenient to take the basic functionality out of your frontend and put it directly to the server - speed is also much better. And if you are tired to try to get Access to do what you want: use pl/pgsql

    hth
    Last edited by lgkf; 10-29-2005 at 07:29 AM. Reason: code tags missing ;(

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •