Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 36540475E7C for ; Sun, 26 May 2002 11:52:01 -0400 (EDT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by postgresql.org (Postfix) with ESMTP id 4114F475E79 for ; Sun, 26 May 2002 11:51:55 -0400 (EDT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 474DCD62F; Sun, 26 May 2002 08:52:00 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 3CFC55C05; Sun, 26 May 2002 08:52:00 -0700 (PDT) Date: Sun, 26 May 2002 08:52:00 -0700 (PDT) From: Stephan Szabo To: "||//::..-cwhisperer-..:://||" Cc: Subject: Re: uinique identifier In-Reply-To: <9069492264.20020526125335@vo.lu> Message-ID: <20020526084942.O1248-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200205/276 X-Sequence-Number: 7911 On Sun, 26 May 2002, ||//::..-cwhisperer-..:://|| wrote: > hi, > > I want to create an unique identifier for all the tables in my db. > > as paramater I pass the length of the identifier and the table name: > > here my function > > DROP FUNCTION ui_alz_table (int4,varchar); > > CREATE FUNCTION ui_alz_table (int4,varchar) RETURNS varchar AS ' > > DECLARE > iLoop int4; > result varchar; > nr int4; > query_string varchar; > > BEGIN > result := ''''; > nr := 1; > > IF ($1>0) AND ($1 < 255) THEN > WHILE nr > 0 LOOP > FOR iLoop in 1 .. $1 LOOP > result := result || chr(int4(random()*25)+65); > END LOOP; > query_string := ''Select * from ''|| $2 || '' where id = '' || result; I think you probably want to use quote_ident on $2 and you'll want to single quote result since otherwise you'll get a query string like: select * from foo where id=FADFDFAD;