pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
problem with automatic altering of groups
3+ messages / 2 participants
[nested] [flat]

* problem with automatic altering of groups
@ 2003-08-20 21:09  Matthias Nagl <mnagl@web.de>
  0 siblings, 0 replies; 3+ messages in thread

From: Matthias Nagl @ 2003-08-20 21:09 UTC (permalink / raw)
  To: pgsql-sql

Hello, 
 
is ist possible to write a function that alters the group of a given user like the following should do in my 
opinion (I'd like to use it in a rule): 
 
CREATE FUNCTION set_group (text, integer) RETURNS text AS ' 
	ALTER GROUP userlevel1 DROP USER $1; ALTER GROUP userlevel2 DROP USER $1; ALTER GROUP 
userlevel3 DROP USER $1; 
	ALTER GROUP userlevel4 DROP USER $1; ALTER GROUP userlevel5 DROP USER $1; 
	CASE $2 
		WHEN 5 THEN 
			(ALTER GROUP userlevel5 ADD USER $1) 
		WHEN 4 THEN 
			(ALTER GROUP userlevel5 ADD USER $1; ALTER GROUP userlevel4 ADD USER $1;) 
		[...] 
	END; 
	SELECT ''; 
' LANGUAGE 'SQL'; 
 
I don't understand why this function ist refused by postgresql with an parse error at the first $1 as ist every 
other method I tryed to get postgres making an "alter group" with a variable. I'd be very happy if someone 
could help... 
 
yours 
 
Matthias Nagl 
__________________________________________________________________________
Die sicherste Form der Kommunikation: E-Mails verschluesseln, Spam-Filter,
Adressverifizierung, digitale Unterschrift: http://freemail.web.de




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

* problem with automatic altering of groups
@ 2003-08-20 21:18  Matthias Nagl <mnagl@web.de>
  0 siblings, 1 reply; 3+ messages in thread

From: Matthias Nagl @ 2003-08-20 21:18 UTC (permalink / raw)
  To: pgsql-sql

"Matthias Nagl" <mnagl@web.de> schrieb am 20.08.03 23:09:03: 
Hello,  
  
is ist possible to write a function that alters the group of a given user like the following should do in my  
opinion (I'd like to use it in a rule):  
  
CREATE FUNCTION set_group (text, integer) RETURNS text AS '  
	ALTER GROUP userlevel1 DROP USER $1; ALTER GROUP userlevel2 DROP USER $1; ALTER GROUP  
userlevel3 DROP USER $1;  
	ALTER GROUP userlevel4 DROP USER $1; ALTER GROUP userlevel5 DROP USER $1;  
	CASE $2  
		WHEN 5 THEN  
			(ALTER GROUP userlevel5 ADD USER $1)  
		WHEN 4 THEN  
			(ALTER GROUP userlevel5 ADD USER $1; ALTER GROUP userlevel4 ADD USER $1;)  
		[...]  
	END;  
	SELECT '';  
' LANGUAGE 'SQL';  
  
I don't understand why this function ist refused by postgresql with an parse error at the first $1 as ist every  
other method I tryed to get postgres making an "alter group" with a variable. I'd be very happy if someone  
could help...  
  
yours  
  
Matthias Nagl  
 
__________________________________________________________________________
Die sicherste Form der Kommunikation: E-Mails verschluesseln, Spam-Filter,
Adressverifizierung, digitale Unterschrift: http://freemail.web.de




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

* Re: problem with automatic altering of groups
@ 2003-08-20 21:32  Josh Berkus <josh@agliodbs.com>
  parent: Matthias Nagl <mnagl@web.de>
  0 siblings, 0 replies; 3+ messages in thread

From: Josh Berkus @ 2003-08-20 21:32 UTC (permalink / raw)
  To: Matthias Nagl <mnagl@web.de>; pgsql-sql

Matthias,

> I don't understand why this function ist refused by postgresql with an parse 
error at the first $1 as ist every  
> other method I tryed to get postgres making an "alter group" with a 
variable. I'd be very happy if someone  
> could help...  

You can't substitute variables for object names.   If you need to construct 
dynamic query strings, use PL/pgSQL and EXECUTE:

sql_qry := ''ALTER GROUP '' || $group || '' ADD USER '' || $user;
EXECUTE sql_query;


-- 
-Josh Berkus
 Aglio Database Solutions
 San Francisco




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


end of thread, other threads:[~2003-08-20 21:32 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-08-20 21:09 problem with automatic altering of groups Matthias Nagl <mnagl@web.de>
2003-08-20 21:18 problem with automatic altering of groups Matthias Nagl <mnagl@web.de>
2003-08-20 21:32 ` Josh Berkus <josh@agliodbs.com>

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