Associative Operators? (Was: Re: [NOVICE] Out of frying pan, into fire)

Started by Clark Evansalmost 27 years ago7 messages
#1Clark Evans
clark.evans@manhattanproject.com

Seth McQuale pointed out that the follwing does not work:
SELECT LASTNAME || ',' || FIRSTNAME [AS] NAME FROM FRIENDS;

The solution, was:
SELECT ( LASTNAME || ',' ) || FIRSTNAME AS NAME FROM FRIENDS;

I looked at pg_operator and didn't see any flag to mark
an operator as 'associative'. Perhaps if we added a flag
like this, the re-write system could be modified to handle
cases like this.

Thoughts?

Clark Evans

#2Bruce Momjian
maillist@candle.pha.pa.us
In reply to: Clark Evans (#1)
Re: [HACKERS] Associative Operators? (Was: Re: [NOVICE] Out of frying pan, into fire)

Seth McQuale pointed out that the follwing does not work:
SELECT LASTNAME || ',' || FIRSTNAME [AS] NAME FROM FRIENDS;

The solution, was:
SELECT ( LASTNAME || ',' ) || FIRSTNAME AS NAME FROM FRIENDS;

I looked at pg_operator and didn't see any flag to mark
an operator as 'associative'. Perhaps if we added a flag
like this, the re-write system could be modified to handle
cases like this.

Thoughts?

Clark Evans

My guess is that we should auto-left-associate functions like || if no
parens are present. It would be a small change to the parser.

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#3Clark Evans
clark.evans@manhattanproject.com
In reply to: Bruce Momjian (#2)
Re: [HACKERS] Associative Operators? (Was: Re: [NOVICE] Out of frying pan, into fire)

Bruce Momjian wrote:

My guess is that we should auto-left-associate functions like || if no
parens are present. It would be a small change to the parser.

I was trying to describe a more general solution,
where the operator is marked if it is associative
when it is created. This would allow the same
mechanism to be used for user defined types.

:) Clark

#4J.M.
darcy@druid.net
In reply to: Bruce Momjian (#2)
Re: [HACKERS] Associative Operators? (Was: Re: [NOVICE] Out of frying pan, into fire)

Thus spake Bruce Momjian

I looked at pg_operator and didn't see any flag to mark
an operator as 'associative'. Perhaps if we added a flag
like this, the re-write system could be modified to handle
cases like this.

My guess is that we should auto-left-associate functions like || if no
parens are present. It would be a small change to the parser.

And wouldn't require a dump/reload.

-- 
D'Arcy J.M. Cain <darcy@{druid|vex}.net>   |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 424 2871     (DoD#0082)    (eNTP)   |  what's for dinner.
#5Clark Evans
clark.evans@manhattanproject.com
In reply to: J.M. (#4)
Re: [HACKERS] Associative Operators? (Was: Re: [NOVICE] Out of frying pan, into fire)

"D'Arcy J.M. Cain" wrote:

And wouldn't require a dump/reload.

Why would this require a dump/reload? It would seem
to me that this would only be needed if you changed
the database storage system? Am I missing something?

Clark

#6Clark Evans
clark.evans@manhattanproject.com
In reply to: J.M. (#4)
Re: [HACKERS] Associative Operators? (Was: Re: [NOVICE] Out of frying pan, into fire)

"D'Arcy J.M. Cain" wrote:

And wouldn't require a dump/reload.

Ooh. If you change pg_operators and add a column. Ok.
For the new version, don't they have to do this anyway?

Clark

#7Bruce Momjian
maillist@candle.pha.pa.us
In reply to: Clark Evans (#1)
Re: [HACKERS] Associative Operators? (Was: Re: [NOVICE] Out of frying pan, into fire)

This is fixed in 6.5 beta.

Seth McQuale pointed out that the follwing does not work:
SELECT LASTNAME || ',' || FIRSTNAME [AS] NAME FROM FRIENDS;

The solution, was:
SELECT ( LASTNAME || ',' ) || FIRSTNAME AS NAME FROM FRIENDS;

I looked at pg_operator and didn't see any flag to mark
an operator as 'associative'. Perhaps if we added a flag
like this, the re-write system could be modified to handle
cases like this.

Thoughts?

Clark Evans

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026