Thread: plpgsql vs. SQL in stored procedures
Is there a way to declare variables and use IF in plain SQL, not in plpgsql inside stored procedures?
mail@webthatworks.it (Ivan Sergio Borgonovo) wrote: > Is there a way to declare variables and use IF in plain SQL, not in > plpgsql inside stored procedures? The forthcoming support for recursive queries using a WITH clause might provide, after a fashion, a way to declare variables. As for IF, there is a functional equivalent to it in the form of the SQL standard CASE statement. -- select 'cbbrowne' || '@' || 'ntlug.org'; http://www.ntlug.org/~cbbrowne/linuxxian.html "How should I know if it works? That's what beta testers are for. I only coded it." (Attributed to Linus Torvalds, somewhere in a posting)
On Wed, 31 Mar 2004 03:31:01 -0500 Christopher Browne <cbbrowne@acm.org> wrote: > The forthcoming support for recursive queries using a WITH clause > might provide, after a fashion, a way to declare variables. I think I'll have to work with pg 7.3 Does this translate to: you won't be able to use variables? I was used to do stuff like this with MS SQL create proc sp_getuid @uid uniqueidentifier as delete from auth where lapse<dateadd(mi,-25,getdate()) declare @R_ID int set @R_ID=(select R_ID from auth where lapse>dateadd(mi,-10,getdate()) and A_ID=@uid) if (@R_ID is null) begin delete from auth where A_ID=@uid select null as R_ID end else begin update auth setlapse=getdate() where A_ID=@uid select @R_ID as R_ID end Does it mean that to have variables in SP I'll have to use plpgsql in spite of plain SQL? > As for IF, there is a functional equivalent to it in the form of the > SQL standard CASE statement. TY for the refreshing pointer. I was looking in the wrong place.
On Wednesday 31 March 2004 12:07, Ivan Sergio Borgonovo wrote: > > I was used to do stuff like this with MS SQL > > create proc sp_getuid @uid uniqueidentifier [snip] > Does it mean that to have variables in SP I'll have to use plpgsql > in spite of plain SQL? Yep - just like there you were using transact-sql (if I remember its name correctly) rather than sql. The syntax is different (plpgsql bares a startling resemblance to the Oracle approach), the purpose of each is the same. -- Richard Huxton Archonet Ltd