pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feeduinique identifier
3+ messages / 3 participants
[nested] [flat]
* uinique identifier
@ 2002-05-26 10:53 ||//::..-cwhisperer-..:://|| <cwhisperer@vo.lu>
2002-05-26 15:52 ` Re: uinique identifier Stephan Szabo <sszabo@megazone23.bigpanda.com>
2002-05-27 01:35 ` Re: uinique identifier Christopher Kings-Lynne <chriskl@familyhealth.com.au>
0 siblings, 2 replies; 3+ messages in thread
From: ||//::..-cwhisperer-..:://|| @ 2002-05-26 10:53 UTC (permalink / raw)
To: pgsql-sql
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;
EXECUTE query_string;
IF NOT FOUND THEN
nr := 0;
END IF;
END LOOP;
RETURN result;
END IF;
END;
' LANGUAGE 'plpgsql';
in the for loop I create the unique identifier and whith the
query_string I check whetherit exists or not.
but I get an error 'Attribute xxxx not found' and I don't know what to to with it.
thx for your help
--
Best regards,
||//::..-cwhisperer-..:://|| mailto:cwhisperer@vo.lu
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: uinique identifier
2002-05-26 10:53 uinique identifier ||//::..-cwhisperer-..:://|| <cwhisperer@vo.lu>
@ 2002-05-26 15:52 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
1 sibling, 0 replies; 3+ messages in thread
From: Stephan Szabo @ 2002-05-26 15:52 UTC (permalink / raw)
To: ||//::..-cwhisperer-..:://|| <cwhisperer@vo.lu>; +Cc: 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;
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: uinique identifier
2002-05-26 10:53 uinique identifier ||//::..-cwhisperer-..:://|| <cwhisperer@vo.lu>
@ 2002-05-27 01:35 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
1 sibling, 0 replies; 3+ messages in thread
From: Christopher Kings-Lynne @ 2002-05-27 01:35 UTC (permalink / raw)
To: cwhisperer <cwhisperer@vo.lu>; pgsql-sql
What's wrong with using the OID column of pg_class or the OID column of your
table?
Chris
----- Original Message -----
From: "||//::..-cwhisperer-..:://||" <cwhisperer@vo.lu>
To: <pgsql-sql@postgresql.org>
Sent: Sunday, May 26, 2002 3:53 AM
Subject: [SQL] uinique identifier
> 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;
> EXECUTE query_string;
> IF NOT FOUND THEN
> nr := 0;
> END IF;
> END LOOP;
> RETURN result;
> END IF;
> END;
> ' LANGUAGE 'plpgsql';
>
> in the for loop I create the unique identifier and whith the
> query_string I check whetherit exists or not.
>
> but I get an error 'Attribute xxxx not found' and I don't know what to to
with it.
>
> thx for your help
>
>
>
> --
> Best regards,
> ||//::..-cwhisperer-..:://||
mailto:cwhisperer@vo.lu
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2002-05-27 01:35 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-05-26 10:53 uinique identifier ||//::..-cwhisperer-..:://|| <cwhisperer@vo.lu>
2002-05-26 15:52 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
2002-05-27 01:35 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
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