Thread: DISTINCT ON

DISTINCT ON

From
Rudi Starcevic
Date:
Hi,

Just quickly, DISTINCT ON - Is that Postgresql only ?
Thanks



Re: DISTINCT ON

From
"Christopher Kings-Lynne"
Date:
Don't know.  I've seen it elsewhere so it might even be "standard".

Chris

> -----Original Message-----
> From: pgsql-sql-owner@postgresql.org
> [mailto:pgsql-sql-owner@postgresql.org]On Behalf Of Rudi Starcevic
> Sent: Friday, 13 September 2002 10:50 AM
> To: pgsql-sql@postgresql.org
> Subject: [SQL] DISTINCT ON
> 
> 
> Hi,
> 
> Just quickly, DISTINCT ON - Is that Postgresql only ?
> Thanks
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
> 
> http://www.postgresql.org/users-lounge/docs/faq.html
> 



Assignments in PL/pgSQL

From
"Michael Paesold"
Date:
Hi all,

although this is not really SQL, but PL/pgSQL, I hope this is the right
place to ask.

I have written a complex triggers. It works very well. Just now I have
realized that I have used the = operater for variable assignments, instead
of the := operater. To my suprise, there was no error or warning, and the
store procedure works very well!

e.g.
NEW.someval = rec.someother;
works as well as
NEW.someval := rec.someother;

Can you confirm that both are valid? Can someone explain this?
And is it safe to use the former syntax?

Best Regards,
Michael Paesold





Re: DISTINCT ON

From
"Chad Thompson"
Date:
According to a recent thread Re: [SQL] Select the max on a field
Jeff Eckerman said:

>If you don't mind a non-portable feature, DISTINCT ON
>should do what you want.  Something like:
>SELECT DISTINCT ON (att_2) att_1, att_2, att_3, att_4
>FROM table
>ORDER BY att_2, att_1 DESC;
I couldnt find anything in the docs, but it acording to this it isnt standard
 
Thanks
Chad
 
----- Original Message -----
From: "Christopher Kings-Lynne" <chriskl@familyhealth.com.au>
Sent: Thursday, September 12, 2002 8:48 PM
Subject: Re: [SQL] DISTINCT ON

> Don't know.  I've seen it elsewhere so it might even be "standard".
>
> Chris
>
> > -----Original Message-----
> > From:
pgsql-sql-owner@postgresql.org
> > [mailto:pgsql-sql-owner@postgresql.org]On Behalf Of Rudi Starcevic
> > Sent: Friday, 13 September 2002 10:50 AM
> > To:
pgsql-sql@postgresql.org
> > Subject: [SQL] DISTINCT ON
> >
> >
> > Hi,
> >
> > Just quickly, DISTINCT ON - Is that Postgresql only ?
> > Thanks
> >
 
 

Re: Assignments in PL/pgSQL

From
Josh Berkus
Date:
Michael,

> although this is not really SQL, but PL/pgSQL, I hope this is the right
> place to ask.

This is the right place.

> I have written a complex triggers. It works very well. Just now I have
> realized that I have used the = operater for variable assignments, instead
> of the := operater. To my suprise, there was no error or warning, and the
> store procedure works very well!
>
> e.g.
> NEW.someval = rec.someother;
> works as well as
> NEW.someval := rec.someother;
>
> Can you confirm that both are valid? Can someone explain this?
> And is it safe to use the former syntax?

I'm very surprised, too.   The "=" syntax is not per spec; my guess is,
somebody coded in compatibility for DB conversion purposes and left it there.
Jan?  Tom?

--
-Josh BerkusAglio Database SolutionsSan Francisco



Re: Assignments in PL/pgSQL

From
Joe Conway
Date:
Josh Berkus wrote:
> I'm very surprised, too.   The "=" syntax is not per spec; my guess is, 
> somebody coded in compatibility for DB conversion purposes and left it there.  
> Jan?  Tom?
> 

I also noticed this the other day while messing with the plpgsql lexer:

/* ---------- * The keyword rules * ---------- */
:=        { return K_ASSIGN; }
=         { return K_ASSIGN; }

This code goes back to the original scan.l from 1998. I'm guessing it has 
always worked, but was never documented -- but I've been known to be wrong 
sometimes ;-). Hopefully Jan will chime in.

Joe



Re: Assignments in PL/pgSQL

From
Jan Wieck
Date:
Josh Berkus wrote:
> 
> Michael,
> 
> > although this is not really SQL, but PL/pgSQL, I hope this is the right
> > place to ask.
> 
> This is the right place.
> 
> > I have written a complex triggers. It works very well. Just now I have
> > realized that I have used the = operater for variable assignments, instead
> > of the := operater. To my suprise, there was no error or warning, and the
> > store procedure works very well!
> >
> > e.g.
> > NEW.someval = rec.someother;
> > works as well as
> > NEW.someval := rec.someother;
> >
> > Can you confirm that both are valid? Can someone explain this?
> > And is it safe to use the former syntax?
> 
> I'm very surprised, too.   The "=" syntax is not per spec; my guess is,
> somebody coded in compatibility for DB conversion purposes and left it there.
> Jan?  Tom?

Er ... I don't recall completely, maybe it was more compatibility
to my own lazyness ;-/ (typing a colon means Shift-and-semicolon
... that's 2 saved keystrokes per assignment ... what do you
think where I save all the keystrokes I need to write email like
this?).

Jan

-- 
#======================================================================#
# It's easier to get forgiveness for being wrong than for being
right. #
# Let's break this rule - forgive
me.                                  #
#==================================================
JanWieck@Yahoo.com #


Re: Assignments in PL/pgSQL

From
Josh Berkus
Date:
Jan,

> Er ... I don't recall completely, maybe it was more compatibility
> to my own lazyness ;-/ (typing a colon means Shift-and-semicolon
> ... that's 2 saved keystrokes per assignment ... what do you
> think where I save all the keystrokes I need to write email like
> this?).

Hmmm. Well, as long as it doesn't cause any problems, why not keep it?

Surely if it caused bugs, we'd have heard by now.

--
-Josh BerkusAglio Database SolutionsSan Francisco