pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
plpgsql vs. SQL in stored procedures
4+ messages / 3 participants
[nested] [flat]

* plpgsql vs. SQL in stored procedures
@ 2004-03-30 22:08  Ivan Sergio Borgonovo <mail@webthatworks.it>
  0 siblings, 1 reply; 4+ messages in thread

From: Ivan Sergio Borgonovo @ 2004-03-30 22:08 UTC (permalink / raw)
  To: pgsql-sql

Is there a way to declare variables and use IF in plain SQL, not in
plpgsql inside stored procedures?



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

* Re: plpgsql vs. SQL in stored procedures
@ 2004-03-31 08:31  Christopher Browne <cbbrowne@acm.org>
  parent: Ivan Sergio Borgonovo <mail@webthatworks.it>
  0 siblings, 1 reply; 4+ messages in thread

From: Christopher Browne @ 2004-03-31 08:31 UTC (permalink / raw)
  To: pgsql-sql

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)



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

* Re: plpgsql vs. SQL in stored procedures
@ 2004-03-31 11:07  Ivan Sergio Borgonovo <mail@webthatworks.it>
  parent: Christopher Browne <cbbrowne@acm.org>
  0 siblings, 1 reply; 4+ messages in thread

From: Ivan Sergio Borgonovo @ 2004-03-31 11:07 UTC (permalink / raw)
  To: pgsql-sql

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 set lapse=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.




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

* Re: plpgsql vs. SQL in stored procedures
@ 2004-03-31 12:06  Richard Huxton <dev@archonet.com>
  parent: Ivan Sergio Borgonovo <mail@webthatworks.it>
  0 siblings, 0 replies; 4+ messages in thread

From: Richard Huxton @ 2004-03-31 12:06 UTC (permalink / raw)
  To: Ivan Sergio Borgonovo <mail@webthatworks.it>; pgsql-sql

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



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


end of thread, other threads:[~2004-03-31 12:06 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-03-30 22:08 plpgsql vs. SQL in stored procedures Ivan Sergio Borgonovo <mail@webthatworks.it>
2004-03-31 08:31 ` Christopher Browne <cbbrowne@acm.org>
2004-03-31 11:07   ` Ivan Sergio Borgonovo <mail@webthatworks.it>
2004-03-31 12:06     ` Richard Huxton <dev@archonet.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