Re: uinique identifier

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: "||//::(dot)(dot)-cwhisperer-(dot)(dot):://||" <cwhisperer(at)vo(dot)lu>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: uinique identifier
Date: 2002-05-26 15:52:00
Message-ID: 20020526084942.O1248-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


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;

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Christopher Kings-Lynne 2002-05-27 01:35:53 Re: uinique identifier
Previous Message ||//::..-cwhisperer-..:://|| 2002-05-26 10:53:35 uinique identifier