Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-24 Thread scott.marlowe
On Sun, 23 Mar 2003, Kevin Brown wrote:

 Joe Conway wrote:
  Jason Earl wrote:
  Actually, I think it was someone else (Joe???) that is doing the leg
  work, and he was the one choosing explode / implode and getting
  gruff for it, so I was just stepping in and defending his decision.
  
  Oops, my bad.  My brain must already think that it is the weekend.  My
  reasoning still stands, though.  Whoever writes the code gets to pick
  the names (assuming, of course, that they can get them past the rest
  of the PostgreSQL hackers).
  
  dons flame proof suit
  Yup, that was me. I was watching from the sidelines ;-)
  
  I'll get on with coding and try to consider all of the input when it 
  comes to picking the names. In the end, it will depend on whatever the 
  guys with commit access will live with, so I'm not going to worry about 
  it too much.
  /dons flame proof suit
 
 My 2 cents:
 
 Use split and merge.  Avoids the join issue and avoids the
 implode/explode issue too.  :-)

Isn't merge a new SQL keyword in SQL99 or SQL03?


---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-24 Thread Joe Conway
scott.marlowe wrote:
On Sun, 23 Mar 2003, Kevin Brown wrote:
Use split and merge.  Avoids the join issue and avoids the
implode/explode issue too.  :-)
Isn't merge a new SQL keyword in SQL99 or SQL03?
Yup, in SQL200x at least:
14.9 merge statement
Function
  Conditionally update rows of a table, or insert new rows into a table,
  or both.
Format
  merge statement ::=
MERGE INTO target table [ [ AS ] merge correlation name ]
USING table reference
ON search condition merge operation specification
At the risk of stirring up a debate again, my latest thoughts were to 
define the two functions as:

  str_to_array(str TEXT, delim TEXT) returns TEXT[]
  array_to_str(array ANYARRAY, delim TEXT) returns TEXT
Joe

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-23 Thread Kevin Brown
Joe Conway wrote:
 Jason Earl wrote:
 Actually, I think it was someone else (Joe???) that is doing the leg
 work, and he was the one choosing explode / implode and getting
 gruff for it, so I was just stepping in and defending his decision.
 
 Oops, my bad.  My brain must already think that it is the weekend.  My
 reasoning still stands, though.  Whoever writes the code gets to pick
 the names (assuming, of course, that they can get them past the rest
 of the PostgreSQL hackers).
 
 dons flame proof suit
 Yup, that was me. I was watching from the sidelines ;-)
 
 I'll get on with coding and try to consider all of the input when it 
 comes to picking the names. In the end, it will depend on whatever the 
 guys with commit access will live with, so I'm not going to worry about 
 it too much.
 /dons flame proof suit

My 2 cents:

Use split and merge.  Avoids the join issue and avoids the
implode/explode issue too.  :-)


-- 
Kevin Brown   [EMAIL PROTECTED]


---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-14 Thread scott.marlowe
On 13 Mar 2003, Greg Stark wrote:

 
 Joe Conway [EMAIL PROTECTED] writes:
 
  I'm leaning toward implode() and explode() now anyway because split() uses a
  regex for the delimiter in PHP (and probably Perl), and I was not planning to
  get that fancy.
 
 PHP isn't exactly an exemplar for great language design.
 
 explode/implode are terribly non-self-descriptive names. Someone seeing them
 for the first time wouldn't really have any clue what they did and would have
 zero chance of guessing their names to find them in an index.
 
 I would suggest join_str() and split_str() if join is too sensitive a word
 for an sql language.

I disagree on both your points.  I'll not address the first one, but the 
use of explode / implode to me was obvious the first time I saw it years 
ago.  It's used by many other languages than PHP, and is as obvious in 
meaning to me as join or split.

In fact, to me, join and split are string functions, not array functions.  
explode and implode, otoh, are more obviously array functions.

Here's the short list from 4 pages of google search for explode implode 
language -php:

Lotusscript
ML
GIML
Lisp
vbscript
Scheme
ADA
ICI
SML
REX

You're quick to throw out a trollish barb against PHP without any 
real discussion as to why it's such a horrible language.  I have to say 
the quality of code I've seen come out of the PHP development community is 
signifigantly better than what I've seen coming out of the Perl community 
lately, and often has much better use of OO methodologies and is generally 
more easily understood than the equivalent Perl code.

If you don't like PHP, dont use it.  If you don't like a proposal has, 
argue against that proposal.  Please stop trolling against PHP.  it's 
unsightly and unprofessional and doesn't belong in this list.


---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-14 Thread Greg Stark

scott.marlowe [EMAIL PROTECTED] writes:

 You're quick to throw out a trollish barb against PHP without any 
 real discussion as to why it's such a horrible language.  

No need to be so sensitive. It was just a humorous way of making the point
that just because PHP does something doesn't mean it's necessarily the best
idea. Suffice it to say I disagree about the quality of PHP language design
but it wasn't the point of the comment nor is it on topic.

Do you really think someone looking for a function to break up a string into a
list of strings would ever think of looking up explode in an index if he
hadn't already used PHP or (shudder) VBScript?

Oops, there I go again.

--
greg


---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-14 Thread scott.marlowe
On 14 Mar 2003, Greg Stark wrote:

 
 scott.marlowe [EMAIL PROTECTED] writes:
 
  You're quick to throw out a trollish barb against PHP without any 
  real discussion as to why it's such a horrible language.  
 
 No need to be so sensitive. It was just a humorous way of making the point
 that just because PHP does something doesn't mean it's necessarily the best
 idea. Suffice it to say I disagree about the quality of PHP language design
 but it wasn't the point of the comment nor is it on topic.
 
 Do you really think someone looking for a function to break up a string into a
 list of strings would ever think of looking up explode in an index if he
 hadn't already used PHP or (shudder) VBScript?
 
 Oops, there I go again.

Let me answer your question with a question:

Is anyone who is familiar with SQL syntax gonna look for join when 
thinking about arrays? 


---(end of broadcast)---
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-14 Thread Christopher Browne
 Do you really think someone looking for a function to break up a
 string into a list of strings would ever think of looking up explode
 in an index if he hadn't already used PHP or (shudder) VBScript?

It's also one of the classic examples of things used in introductory
courses on Lisp that are absolutely counterproductive because no one
would ever use (EXPLODE FOO) in /real/ code...
--
If this was helpful, http://svcs.affero.net/rm.php?r=cbbrowne rate me
http://cbbrowne.com/info/advocacy.html
Go, lemmings, go!

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-14 Thread Þórhallur Hálfdánarson
-*- Greg Stark [EMAIL PROTECTED] [ 2003-03-14 17:43 ]:
 Do you really think someone looking for a function to break up a string into a
 list of strings would ever think of looking up explode in an index if he
 hadn't already used PHP or (shudder) VBScript?

If one had gotten used to Lotus Notes, sure. ;



-- 
Regards,
Tolli
[EMAIL PROTECTED]

---(end of broadcast)---
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-14 Thread scott.marlowe
On Fri, 14 Mar 2003, Christopher Browne wrote:

  Do you really think someone looking for a function to break up a
  string into a list of strings would ever think of looking up explode
  in an index if he hadn't already used PHP or (shudder) VBScript?
 
 It's also one of the classic examples of things used in introductory
 courses on Lisp that are absolutely counterproductive because no one
 would ever use (EXPLODE FOO) in /real/ code...

OK, that's enough.  No one's been insulting your coding skills, your 
choice of language or how you use it.  Please return the favor.  That's 
all I'm asking.  It may seem like a throw away line for you, but you are 
both directly insulting many people who have done you no harm.

I vote for explode / implode as easier to type and remember than join_str.  
Also, in the SQL world, it's very likely that a back ground in 
ADA/LISP/REX/PHP is just as common as Perl or Java.

If you've got a point to make, please try to do so in a manner that isn't 
a backhanded slap to others at the same time.


---(end of broadcast)---
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-14 Thread scott.marlowe
On Fri, 14 Mar 2003, Þórhallur Hálfdánarson wrote:

 -*- Greg Stark [EMAIL PROTECTED] [ 2003-03-14 17:43 ]:
  Do you really think someone looking for a function to break up a string into a
  list of strings would ever think of looking up explode in an index if he
  hadn't already used PHP or (shudder) VBScript?
 
 If one had gotten used to Lotus Notes, sure. ;

To try and get back on track...

Let me ask you, if you were looking through a list of array functions 
and you saw explode and implode, and you had no other experience with a 
language that used those keywords, would you, upon seeing them, have some 
idea what they did?

I certainly did the first time I saw them way back when on Rex.  Since 
there was no one around to teach me the religious belief that explode and 
implode are anathema to real programmers, I started using them and was 
quite happy with their performance.  (Sorry, that's a reference to a 
previouis post about real code.  I'll stop the verbal sparring now :-)

I would like to have a single word.  Join and Split are a poor choice 
becuase join already has a very well defined meaning in SQL.  any 
variation that keeps the word join in it is a poor choice because it can 
be confusing.  What other languages have used before is of little 
consequence really, as long as Postgresql's choices are internally 
consistent, are a desriptive word and don't conflict with current key 
words.

The fact that some languages that use explode / implode are not favored by 
certain folks means less than nothing to me.  The names for functions 
should be something that is easily found in the docs both when you don't 
know what it is called and when you do.

Explode may be a little harder to find when you don't know the name yet, 
but since you should be using the table of contents, not the index to look 
up a function whose name you don't know, then all that means is having a 
good table of contents and well layed out docs.

If you do know the function name, you shouldn't have 200 choices in an 
index or a keyword search.  Join, both as a keyword, and as a word, is 
very common in the docs.  Searching for it, I currently find 412 
entries for the word join in the 7.3.2 docs.

Explode, on the other hand, returns 0 count.  So, if someone goes to 
google and searches on site:techdocs.postgresql.org join, he will get 
hundreds of pages back.  If he searches on explode, he would, in the 
future, only find those pages referencing the explode function.

I'll repeat, the part about looking in an index for a keyword you don't 
know yet is a straw man, and a poor one at that.  If you don't know the 
keyword for a cursor is declare why would you look in the index?  You 
wouldn't, you'd look up cursors in the table of contents and find it that 
way.  Or you'd search for it.  If cursors were used for some other 
function in postgresql (widget counting et. al.) it would make it harder 
to find the entries you wanted for real cursors.


---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-14 Thread Andrew Dunstan
Here's a list of synonyms for join (courtesy of m-w.com):

associate, bracket, coadunate, coagment, coalesce, combine, compound,
concrete, conjoin, conjugate, connect, couple, link, marry, one, relate,
unite, wed, yoke

and for split:

carve, cleave, dissect, dissever, sever, slice, sunder,  cleave, rend, rip,
rive

Personally I think having marry and divorce would be nice ;-)

andrew

(and when this debate is finished we can get back to emacs vs. vi)


---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-14 Thread Jason Earl
scott.marlowe [EMAIL PROTECTED] writes:

 On Fri, 14 Mar 2003, Þórhallur Hálfdánarson wrote:
 
  -*- Greg Stark [EMAIL PROTECTED] [ 2003-03-14 17:43 ]:
   Do you really think someone looking for a function to break up a string into a
   list of strings would ever think of looking up explode in an index if he
   hadn't already used PHP or (shudder) VBScript?
  
  If one had gotten used to Lotus Notes, sure. ;
 
 To try and get back on track...
 
 Let me ask you, if you were looking through a list of array functions 
 and you saw explode and implode, and you had no other experience with a 
 language that used those keywords, would you, upon seeing them, have some 
 idea what they did?

It's all good Scott.  Anyone wanting to use PostgreSQL arrays would
undoubtedly open up the corresponding part of the manual that covers
array functions.  Since there is likely to be less than a page full of
function definitions you could probably call the functions foo() and
bar() and get away with it (please don't).  While I personally think
that join_str and split_str are somewhat more descriptive, implode and
explode are fine.

More importantly, since *you* are the one doing the actual legwork
it's your call.  IMHO that's one of the benefits of actually
submitting code.  You write the code, you get to pick the function
names.  Now, you might have some issues from the rest of the
PostgreSQL hackers if you named the functions marlowe-ify and
un-marlowe-ify, but anything not completely ridiculous should be
fine (and even marlowe-ify would have the advantage of not being a
reserved word in any software I can think of off hand).

As for the rest of the discussion, poking fun at development languages
and tools is an age-old part of computers.  PHP has the disadvantage
of being both very popular, very new, and primarily a web technology
(and of not being Lisp like :) so it draws more than its share of
flames.  It's all good fun.

Jason


---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-14 Thread scott.marlowe
On 14 Mar 2003, Jason Earl wrote:

 It's all good Scott.  Anyone wanting to use PostgreSQL arrays would
 undoubtedly open up the corresponding part of the manual that covers
 array functions.  Since there is likely to be less than a page full of
 function definitions you could probably call the functions foo() and
 bar() and get away with it (please don't).  While I personally think
 that join_str and split_str are somewhat more descriptive, implode and
 explode are fine.
 
 More importantly, since *you* are the one doing the actual legwork
 it's your call.  IMHO that's one of the benefits of actually
 submitting code.  You write the code, you get to pick the function
 names.  Now, you might have some issues from the rest of the
 PostgreSQL hackers if you named the functions marlowe-ify and
 un-marlowe-ify, but anything not completely ridiculous should be
 fine (and even marlowe-ify would have the advantage of not being a
 reserved word in any software I can think of off hand).
 
 As for the rest of the discussion, poking fun at development languages
 and tools is an age-old part of computers.  PHP has the disadvantage
 of being both very popular, very new, and primarily a web technology
 (and of not being Lisp like :) so it draws more than its share of
 flames.  It's all good fun.

Actually, I think it was someone else (Joe???) that is doing the leg 
work, and he was the one choosing explode / implode and getting gruff for 
it, so I was just stepping in and defending his decision.

I do think using a function name with the word join in it meaning anything 
other than a SQL join is a recipe for confusion though.


---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-14 Thread Joe Conway
Jason Earl wrote:
Actually, I think it was someone else (Joe???) that is doing the leg
work, and he was the one choosing explode / implode and getting
gruff for it, so I was just stepping in and defending his decision.
Oops, my bad.  My brain must already think that it is the weekend.  My
reasoning still stands, though.  Whoever writes the code gets to pick
the names (assuming, of course, that they can get them past the rest
of the PostgreSQL hackers).
dons flame proof suit
Yup, that was me. I was watching from the sidelines ;-)
I'll get on with coding and try to consider all of the input when it 
comes to picking the names. In the end, it will depend on whatever the 
guys with commit access will live with, so I'm not going to worry about 
it too much.
/dons flame proof suit

Joe

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
   (send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-14 Thread D'Arcy J.M. Cain
On Friday 14 March 2003 13:24, scott.marlowe wrote:
 I vote for explode / implode as easier to type and remember than join_str.
 Also, in the SQL world, it's very likely that a back ground in
 ADA/LISP/REX/PHP is just as common as Perl or Java.

If we're voting I vote for join/split.  Implode and explode just sound 
unprofessional to me.  Minor point but it's just preference, right?

-- 
D'Arcy J.M. Cain [EMAIL PROTECTED]|vex}.net   |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-14 Thread scott.marlowe
On Fri, 14 Mar 2003, D'Arcy J.M. Cain wrote:

 On Friday 14 March 2003 13:24, scott.marlowe wrote:
  I vote for explode / implode as easier to type and remember than join_str.
  Also, in the SQL world, it's very likely that a back ground in
  ADA/LISP/REX/PHP is just as common as Perl or Java.
 
 If we're voting I vote for join/split.  Implode and explode just sound 
 unprofessional to me.  Minor point but it's just preference, right?

Sorry, but that's really not much of a reason.  I listed several reasons 
why ANY OTHER CHOICE is better, not just explode / implode.

I think those reasons make sense.  You didn't address any of them in your 
choice, only the fact that you don't like explode/implode, so I'll assume 
you didn't have any real issues with the reasons I listed for not using 
join/split, just with the words explode/implode.

If that's the case, the perhaps a compromise is in order, i.e. anything 
BUT join/split or explode/implode.

But then the problem is that there are probably no other common words I'm 
familiar with that any other languages use to go from string to array and 
back that we are likely to glom onto.


---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-13 Thread Peter Eisentraut
OK, let's look at these more closely:

array_push(anyarray, anyelement) returns anyarray

The standard spelling for that appears to be
somearray || ARRAY[element]
which also has the nice property that it is commutative.

array_pop(anyarray) returns anyelement

That appears to mean that you return somearray[0] and alter the array as a
side effect.  How do you plan to do that?

array_subscript(anyarray, int) yields anyelement

That's just somearray[x], no?

singleton_array(anyelement) returns anyarray

That's ARRAY[element].

split(text, text) returns text[]
   - split string into array on delimiter
implode(text[], text) returns text
   - join array elements into a string using given string delimiter

I can live with these, but perhaps we should choose some not-so-generic
names.

-- 
Peter Eisentraut   [EMAIL PROTECTED]


---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-13 Thread Tom Lane
Peter Eisentraut [EMAIL PROTECTED] writes:
 OK, let's look at these more closely:

 array_push(anyarray, anyelement) returns anyarray

 The standard spelling for that appears to be
 somearray || ARRAY[element]
 which also has the nice property that it is commutative.

Sure ... but that just means that || is the operator name for the
underlying array_push function.  We still need a way to declare this
operation as a function.


 array_pop(anyarray) returns anyelement

 That appears to mean that you return somearray[0] and alter the array as a
 side effect.  How do you plan to do that?

Yeah, I wasn't thinking very clearly there...


 array_subscript(anyarray, int) yields anyelement

 That's just somearray[x], no?

Yes.  But the fact that we can now represent the semantics of [] as a
function seems to me to indicate that we're on the right track in terms
of generalizing the capabilities of functions.

regards, tom lane

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-13 Thread Joe Conway
Peter Eisentraut wrote:
array_pop(anyarray) returns anyelement
That appears to mean that you return somearray[0] and alter the array
as a side effect.  How do you plan to do that?
I'll give you this one -- doesn't make sense.

split(text, text) returns text[] - split string into array on
delimiter
There was a thread on this last September, and the consensus was that
the function *should* be name split, in order to be consistent with the
similar function existing in Perl and PHP (at least).
implode(text[], text) returns text - join array elements into a
string using given string delimiter
I'm open to opinions on implode() -- I only picked implode() because
that's what it is called in PHP. Any suggestions?
Joe





---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
   (send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-13 Thread johnnnnnn
On Thu, Mar 13, 2003 at 09:53:15AM -0800, Joe Conway wrote:
 implode(text[], text) returns text - join array elements into a
 string using given string delimiter
 
 I'm open to opinions on implode() -- I only picked implode() because
 that's what it is called in PHP. Any suggestions?

In both Perl and Python, that type of function is called join.

-john

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-13 Thread Alvaro Herrera
On Thu, Mar 13, 2003 at 12:00:46PM -0600, johnn wrote:
 On Thu, Mar 13, 2003 at 09:53:15AM -0800, Joe Conway wrote:
  implode(text[], text) returns text - join array elements into a
  string using given string delimiter
  
  I'm open to opinions on implode() -- I only picked implode() because
  that's what it is called in PHP. Any suggestions?
 
 In both Perl and Python, that type of function is called join.

Yeah, and join is also consistent with the inverse function being called
split.  IIRC the equivalent function in PHP is explode().

-- 
Alvaro Herrera (alvherre[a]dcc.uchile.cl)
Si no sabes adonde vas, es muy probable que acabes en otra parte.

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-13 Thread Joe Conway
johnn wrote:
On Thu, Mar 13, 2003 at 09:53:15AM -0800, Joe Conway wrote:
implode(text[], text) returns text - join array elements into a
string using given string delimiter
In both Perl and Python, that type of function is called join.
Hmmm -- I doubt that would fly, although I see it is specifically 
allowed as a function name (func_name_keyword list). Anyone have 
opinions on this either way?

Joe



---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-13 Thread Joe Conway
Alvaro Herrera wrote:
Yeah, and join is also consistent with the inverse function being called
split.  IIRC the equivalent function in PHP is explode().
Actually it looks like PHP supports both explode() and split(), and 
their inverse functions implode() and join(). split() appears to split 
the string by regular expression, whereas explode() splits by a simple 
string separator.

I was not intending to support regex in split(), so maybe the best 
choice of names is explode() and implode()?

Joe

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-13 Thread Rod Taylor
On Thu, 2003-03-13 at 12:53, Joe Conway wrote:
 Peter Eisentraut wrote:
  array_pop(anyarray) returns anyelement
  
  That appears to mean that you return somearray[0] and alter the array
  as a side effect.  How do you plan to do that?
 
 I'll give you this one -- doesn't make sense.
 
  split(text, text) returns text[] - split string into array on
  delimiter
 
 There was a thread on this last September, and the consensus was that
 the function *should* be name split, in order to be consistent with the
 similar function existing in Perl and PHP (at least).
 
  implode(text[], text) returns text - join array elements into a
  string using given string delimiter
 
 I'm open to opinions on implode() -- I only picked implode() because
 that's what it is called in PHP. Any suggestions?

I think implode() and explode() go together.  split() and join() are a
pair.  Pick one ;)

-- 
Rod Taylor [EMAIL PROTECTED]

PGP Key: http://www.rbt.ca/rbtpub.asc


signature.asc
Description: This is a digitally signed message part


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-13 Thread Hannu Krosing
Tom Lane kirjutas N, 13.03.2003 kell 19:12:
 Peter Eisentraut [EMAIL PROTECTED] writes:
  OK, let's look at these more closely:
 
  array_push(anyarray, anyelement) returns anyarray
 
  The standard spelling for that appears to be
  somearray || ARRAY[element]
  which also has the nice property that it is commutative.
 
 Sure ... but that just means that || is the operator name for the
 underlying array_push function.  We still need a way to declare this
 operation as a function.

I think he mant that you just need to conacat for too arrays, no need
for single-element push/append. OTOH a separate push may be more
efficient

contrib/intarray has the following functions (note that they use + for
|| above)

OPERATIONS:

  int[]  int[]  - overlap - returns TRUE if arrays has at least one
common elements.
  int[] @  int[]  - contains - returns TRUE if left array contains
right array
  int[] ~ int[]   - contained - returns TRUE if left array is contained
in right array
  # int[] - return the number of elements in array
  int[] + int - push element to array ( add to end of array)
  int[] + int[]   - merge of arrays (right array added to the end 
of left one)
  int[] - int - remove entries matched by right argument from array
  int[] - int[]   - remove right array from left
  int[] | int - returns intarray - union of arguments
  int[] | int[]   - returns intarray as a union of two arrays
  int[]  int[]   - returns intersection of arrays
  int[] @@ query_int  - returns TRUE if array satisfies query 
   (like '1(2|3)')
  query_int ~~ int[]  - -/-


-
Hannu


---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-13 Thread Tom Lane
Hannu Krosing [EMAIL PROTECTED] writes:
 Tom Lane kirjutas N, 13.03.2003 kell 19:12:
 The standard spelling for that appears to be
 somearray || ARRAY[element]
 which also has the nice property that it is commutative.
 
 Sure ... but that just means that || is the operator name for the
 underlying array_push function.  We still need a way to declare this
 operation as a function.

 I think he mant that you just need to conacat for too arrays, no need
 for single-element push/append.

Oh, I see.  But my point remains: unless you want to take || out of the
domain of operators and make it something hard-wired into the parser,
there has to be an underlying function with a matching signature.  So
all these problems come up anyway.

 contrib/intarray has the following functions (note that they use + for
 || above)

The reason that stuff is still contrib, and not mainstream, is we didn't
have a way to make the functions polymorphic.  One-datatype-at-a-time
interface functions are not appealing, especially not when they have to
be hand-coded in C.  But with the features discussed in this thread, we
could make the intarray functionality datatype-independent --- whereupon
I for one would vote to move it into the mainstream.

regards, tom lane

---(end of broadcast)---
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-13 Thread Tom Lane
Joe Conway [EMAIL PROTECTED] writes:
 In both Perl and Python, that type of function is called join.

 Hmmm -- I doubt that would fly, although I see it is specifically 
 allowed as a function name (func_name_keyword list). Anyone have 
 opinions on this either way?

Good point --- it would work today, but any small tweak in the JOIN
grammar might force us to reserve the keyword altogether.  It'd be
safer to use a name that is not an SQL keyword ...

regards, tom lane

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-13 Thread Joe Conway
Tom Lane wrote:
Joe Conway [EMAIL PROTECTED] writes:
Hmmm -- I doubt that would fly, although I see it is specifically 
allowed as a function name (func_name_keyword list). Anyone have 
opinions on this either way?
Good point --- it would work today, but any small tweak in the JOIN
grammar might force us to reserve the keyword altogether.  It'd be
safer to use a name that is not an SQL keyword ...
I'm leaning toward implode() and explode() now anyway because split() 
uses a regex for the delimiter in PHP (and probably Perl), and I was not 
planning to get that fancy.

Joe



---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faqs/FAQ.html


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-13 Thread Greg Stark

Joe Conway [EMAIL PROTECTED] writes:

 I'm leaning toward implode() and explode() now anyway because split() uses a
 regex for the delimiter in PHP (and probably Perl), and I was not planning to
 get that fancy.

PHP isn't exactly an exemplar for great language design.

explode/implode are terribly non-self-descriptive names. Someone seeing them
for the first time wouldn't really have any clue what they did and would have
zero chance of guessing their names to find them in an index.

I would suggest join_str() and split_str() if join is too sensitive a word
for an sql language.

--
greg


---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-13 Thread Christopher Kings-Lynne
  implode(text[], text) returns text - join array elements into a
  string using given string delimiter
 
 I'm open to opinions on implode() -- I only picked implode() because
 that's what it is called in PHP. Any suggestions?

It's also called 'join' in PHP...

Chris


---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-12 Thread Joe Conway
Tom Lane wrote:
But I think I like better the notion of extending my bound-together-
ANYARRAY-and-ANYELEMENT proposal,
http://archives.postgresql.org/pgsql-hackers/2003-03/msg00319.php
Suppose that we do that, and then further say that ANYARRAY or
ANYELEMENT appearing as the return type implies that the return type
is actually the common element or array type.  Then we have such
useful behaviors as:
array_push(anyarray, anyelement) returns anyarray
array_pop(anyarray) returns anyelement
array_subscript(anyarray, int) yields anyelement
singleton_array(anyelement) yields anyarray
Before I get too far along, I'd like to get some feedback. The attached 
patch implements Tom's bound-together-ANYARRAY-and-ANYELEMENT proposal 
(and includes ANY as well, per earlier discussion). With it, the 
following works:

CREATE OR REPLACE FUNCTION array_push (anyarray, anyelement)
RETURNS anyarray
AS '$libdir/plr','array_push'
LANGUAGE 'C';
regression=# select f1[2] from (select array_push('{1,2}'::integer[],3) 
as f1) as t;
 f1

  2
(1 row)

Does it make sense to commit this now, or should it wait for the other 
changes described below?

The following are my proposed next phases in array support changes. 
Please let me know now if you think any of these won't fly (conceptually):

1) Implement SQL99/200x ARRAY[] changes proposed here:
   http://archives.postgresql.org/pgsql-hackers/2003-03/msg00297.php
   as modified by
   http://archives.postgresql.org/pgsql-hackers/2003-03/msg00315.php
2) Implement the following new builtin functions
 array_push(anyarray, anyelement) returns anyarray
 array_pop(anyarray) returns anyelement
 array_subscript(anyarray, int) yields anyelement
 singleton_array(anyelement) returns anyarray
- any reason not to call this one simply array?
 split(text, text) returns text[]
- split string into array on delimiter
 implode(text[], text) returns text
- join array elements into a string using given string delimiter
3) Modify contrib/array functions as needed and move to the backend. Or
   possibly write equivalent functions from scratch -- I just noticed
   this in contrib/array:
   * This software is distributed under the GNU General Public License
   * either version 2, or (at your option) any later version.
   Is anyone still in contact with Massimo Dal Zotto? Any chance he
   would change the license to BSD?
4) Update User's Guide-Data Types-Arrays documentation and
   create a new section: User's Guide-
 Functions and Operators-
 Array Functions and Operators
Thoughts, comments, objections all welcomed.

Thanks,

Joe
Index: src/backend/parser/parse_coerce.c
===
RCS file: /opt/src/cvs/pgsql-server/src/backend/parser/parse_coerce.c,v
retrieving revision 2.93
diff -c -r2.93 parse_coerce.c
*** src/backend/parser/parse_coerce.c   9 Feb 2003 06:56:28 -   2.93
--- src/backend/parser/parse_coerce.c   12 Mar 2003 16:17:39 -
***
*** 188,194 
  
ReleaseSysCache(targetType);
}
!   else if (targetTypeId == ANYOID ||
 targetTypeId == ANYARRAYOID)
{
/* assume can_coerce_type verified that implicit coercion is okay */
--- 188,194 
  
ReleaseSysCache(targetType);
}
!   else if (targetTypeId == ANYOID || targetTypeId == ANYELEMENTOID ||
 targetTypeId == ANYARRAYOID)
{
/* assume can_coerce_type verified that implicit coercion is okay */
***
*** 325,332 
continue;
}
  
!   /* accept if target is ANY */
!   if (targetTypeId == ANYOID)
continue;
  
/*
--- 325,332 
continue;
}
  
!   /* accept if target is ANY or ANYELEMENT */
!   if (targetTypeId == ANYOID || targetTypeId == ANYELEMENTOID)
continue;
  
/*
Index: src/backend/parser/parse_func.c
===
RCS file: /opt/src/cvs/pgsql-server/src/backend/parser/parse_func.c,v
retrieving revision 1.144
diff -c -r1.144 parse_func.c
*** src/backend/parser/parse_func.c 9 Feb 2003 06:56:28 -   1.144
--- src/backend/parser/parse_func.c 12 Mar 2003 17:46:44 -
***
*** 41,46 
--- 41,50 
   List *fargs,
   Oid *input_typeids,
   Oid *function_typeids);
+ static Oid enforce_generic_type_consistency(Oid *oid_array,
+  
 Oid *true_oid_array,
+  
 int nargs,

Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-12 Thread Tom Lane
Joe Conway [EMAIL PROTECTED] writes:
 +  * If ANY, ANYARRAY, or ANYELEMENT is used for a function's arguments or
 +  * return type, make sure the runtime types are consistent with
 +  * each other. The argument consistency rules are like so:
 +  *
 +  * 1) All arguments declared ANY should have matching datatypes.
 +  * 2) All arguments declared ANYARRAY should have matching datatypes.
 +  * 3) All arguments declared ANYELEMENT should have matching datatypes.
 +  * 4) If there are arguments of both ANYELEMENT and ANYARRAY, make sure
 +  *the runtime scalar argument type is in fact the element type for
 +  *the runtime array argument type.

Hmm.  I don't see why we should drag ANY into this --- it should just be
a no-constraints placeholder, same as before.  What's the gain from
constraining it that you don't get from ANYELEMENT?

 +  * 5) If return type is ANYARRAY, no argument is ANYARRAY or ANYELEMENT,
 +  *leave the return type as is.
 +  *XXX should this case be rejected at the point of function creation?

Probably.  This case could be handled just as well by declaring the
output to be ANY, I'd think.

 +  * 8) If return type is ANYELEMENT, no argument is ANYARRAY or ANYELEMENT
 +  *leave the return type as is.
 +  *XXX should this case be rejected at the point of function creation?

Likewise.  The point of (this reinterpretation of) ANYARRAY and
ANYELEMENT is to let the parser deduce the actual output type.
If it's not going to be able to deduce anything, use ANY instead.

regards, tom lane

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-12 Thread Joe Conway
Tom Lane wrote:
Joe Conway [EMAIL PROTECTED] writes:
+  * If ANY, ANYARRAY, or ANYELEMENT is used for a function's arguments or
+  * return type, make sure the runtime types are consistent with
+  * each other. The argument consistency rules are like so:
Hmm.  I don't see why we should drag ANY into this --- it should just be
a no-constraints placeholder, same as before.  What's the gain from
constraining it that you don't get from ANYELEMENT?
I was thinking of the case
  create function foo(any) returns any
but I guess you're right, it can just as easily be
  create function foo(anyelement) returns anyelement
I'll pull the ANY stuff out.

+  * 5) If return type is ANYARRAY, no argument is ANYARRAY or ANYELEMENT,
+  *leave the return type as is.
+  *XXX should this case be rejected at the point of function creation?
Probably.  This case could be handled just as well by declaring the
output to be ANY, I'd think.
+  * 8) If return type is ANYELEMENT, no argument is ANYARRAY or ANYELEMENT
+  *leave the return type as is.
+  *XXX should this case be rejected at the point of function creation?
Likewise.  The point of (this reinterpretation of) ANYARRAY and
ANYELEMENT is to let the parser deduce the actual output type.
If it's not going to be able to deduce anything, use ANY instead.
OK -- I'll take care of that too.

Thanks,

Joe



---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-12 Thread Peter Eisentraut
Joe Conway writes:

 2) Implement the following new builtin functions
   array_push(anyarray, anyelement) returns anyarray
   array_pop(anyarray) returns anyelement
   array_subscript(anyarray, int) yields anyelement
   singleton_array(anyelement) returns anyarray
  - any reason not to call this one simply array?
   split(text, text) returns text[]
  - split string into array on delimiter
   implode(text[], text) returns text
  - join array elements into a string using given string delimiter

I think this goes too far.  It is just an invitation to people to create
bad database designs by using arrays as lists.  Create an array support
package on gborg if you like, but I feel this should not be in the
mainline.

-- 
Peter Eisentraut   [EMAIL PROTECTED]


---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-12 Thread Joe Conway
Peter Eisentraut wrote:
 Joe Conway writes:

2) Implement the following new builtin functions
  array_push(anyarray, anyelement) returns anyarray
  array_pop(anyarray) returns anyelement
  array_subscript(anyarray, int) yields anyelement
  singleton_array(anyelement) returns anyarray
 - any reason not to call this one simply array?
  split(text, text) returns text[]
 - split string into array on delimiter
  implode(text[], text) returns text
 - join array elements into a string using given string delimiter
I think this goes too far.  It is just an invitation to people to create
bad database designs by using arrays as lists.  Create an array support
package on gborg if you like, but I feel this should not be in the
mainline.
Sorry, I don't agree with that assessment. There are lots of ways people 
can create bad database designs using the CREATE TABLE statement too ;-)

Arrays *do* have a place, and they are supported in SQL99+. We get 
complaints almost daily regarding the poor array support -- this is just 
a step toward improving that. If you want to debate the merit of 
individual functions on that list, let's do that, but to dismiss them 
all with a wave-of-the-hand is too far.

Joe

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faqs/FAQ.html


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-12 Thread Tom Lane
Joe Conway [EMAIL PROTECTED] writes:
 Peter Eisentraut wrote:
 Create an array support package on gborg if you like, but I feel this
 should not be in the mainline.

 Arrays *do* have a place, and they are supported in SQL99+.

FWIW, I'm with Joe on this one.  Arrays have their uses; and it's not
like there are no misusable constructs in SQL ...

regards, tom lane

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-10 Thread Tom Lane
Hannu Krosing [EMAIL PROTECTED] writes:
 Joe Conway kirjutas E, 10.03.2003 kell 05:35:
 CREATE OR REPLACE FUNCTION array_push (anyarray, anyscalar)
 RETURNS anyarray

 could you make it
 RETURNS typeof($1)

Not directly --- we have to fit the return-type info into an OID field.
We could fake it by inventing one or more pseudotypes, SAMEASPARAMn.

But I think I like better the notion of extending my bound-together-
ANYARRAY-and-ANYELEMENT proposal,
http://archives.postgresql.org/pgsql-hackers/2003-03/msg00319.php

Suppose that we do that, and then further say that ANYARRAY or
ANYELEMENT appearing as the return type implies that the return type
is actually the common element or array type.  Then we have such
useful behaviors as:

array_push(anyarray, anyelement) returns anyarray
array_pop(anyarray) returns anyelement
array_subscript(anyarray, int) yields anyelement
singleton_array(anyelement) yields anyarray

The last three cases cannot be handled by a SAMEASPARAM construct.

regards, tom lane

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-10 Thread Joe Conway
Tom Lane wrote:
But I think I like better the notion of extending my bound-together-
ANYARRAY-and-ANYELEMENT proposal,
http://archives.postgresql.org/pgsql-hackers/2003-03/msg00319.php
Suppose that we do that, and then further say that ANYARRAY or
ANYELEMENT appearing as the return type implies that the return type
is actually the common element or array type.  Then we have such
useful behaviors as:
array_push(anyarray, anyelement) returns anyarray
array_pop(anyarray) returns anyelement
array_subscript(anyarray, int) yields anyelement
singleton_array(anyelement) yields anyarray
The last three cases cannot be handled by a SAMEASPARAM construct.
That was my concern also. I like the above.

So if I understand correctly, all instances of anyarray and anyelement 
in a function definition would need to be self-consistent, but the group 
could represent essentially any datatype with its corresponding array 
type. If we need more than one of these self consistent groups, we could 
resort to anyarray1/anyelement1, etc. Does this sound correct?

Also, an implementation question: if I have a type oid for an element, 
what is the preferred method for determining the corresponding array? 
I'm thinking that the most efficient method might be to use the 
element-type name with a '_' prepended to get the array-type oid, but 
that seems ugly. Thoughts?

Thanks,

Joe



---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
   (send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-10 Thread Jason M. Felice
On Mon, Mar 10, 2003 at 09:49:47AM -0500, Tom Lane wrote:
 Hannu Krosing [EMAIL PROTECTED] writes:
  Joe Conway kirjutas E, 10.03.2003 kell 05:35:
  CREATE OR REPLACE FUNCTION array_push (anyarray, anyscalar)
  RETURNS anyarray
 
  could you make it
  RETURNS typeof($1)
 
 Not directly --- we have to fit the return-type info into an OID field.
 We could fake it by inventing one or more pseudotypes, SAMEASPARAMn.
 
 But I think I like better the notion of extending my bound-together-
 ANYARRAY-and-ANYELEMENT proposal,
 http://archives.postgresql.org/pgsql-hackers/2003-03/msg00319.php
 
 Suppose that we do that, and then further say that ANYARRAY or
 ANYELEMENT appearing as the return type implies that the return type
 is actually the common element or array type.  Then we have such
 useful behaviors as:
 
   array_push(anyarray, anyelement) returns anyarray
   array_pop(anyarray) returns anyelement
   array_subscript(anyarray, int) yields anyelement
   singleton_array(anyelement) yields anyarray
 
 The last three cases cannot be handled by a SAMEASPARAM construct.

... typeof($1)[], or a ARRAYELEMSAMEASPARAM construct?



I'm really liking this discussion.  I know this is sort of out there, but
I have found in languages like StandardML and Objective CAML that templatized-
type functions are _extremely_ useful.   These languages type systems are
amazingly powerful (the language syntax is another matter *sigh*).

I'm not necessarily suggesting implementing this, but I just want to feed the
debate a bit.  I view the type system of these guys as the ideal, and would
be in ecstacy if PostgreSQL had it, but I realize implementing the thing would
prolly be far from practical.

First, there are templatized types.  Arrays in PostgreSQL are sort of a 
kludge of templatized types, but they would be defined like so:

type a' array = some definition ...

which means that you are describing an array of some type a' (the apostrophe
indicates a type variable).

You can also create other neat templatized types as an aside:

type a' Nullable = Null | Value of a'

Which means the expressions:
Value 47 -- of type int Nullable
Null -- of type a' Nullable (determined from context)

But then, you could also say:

int array array

Or even:

int Nullable array

Which is somthing you can't in PostgreSQL but would be very nice.  But then
you could say:

let invert_matrix m : a' array array - a' array array = code...

let multiply x : a', y : a' - a' = code ...

You could have more than one type variable in a templatized type or function,
true, but I've never really needed more than one.  I can imagine cases where
it would be useful, but just haven't needed one.

Plus:
* get rid of horrible 'int4_' type hacks for array.
Minus:
* can't use oid to represent exact type, rather a string of oids.
* need second table to hold function type constraints when function
  is templatized.  (or could make it params oid array array, aka
  oid[][]!) Reserve eight or ten oids for template parameter slots
  (in other words, for a' through j' or something).

Warning: I have been called the type nazi g

One other thing from StandardML that I have always wanted in PostgreSQL
(or anywhere else I program, for that matter)- record types. (Warning, this is
also very wishful thinking and out there).

In ML/CAML, a record type is defined like so:

type myrecord = {
x : int,
y : int,
s : string
};

myrecord is actually just type alias, the canonical record definition is:

{s:string, x:int, y:int}

... with the attributes in alphabetical order, because unless you are mucking
with pointers in C, it really doesn't matter what order they are in.  The
first advantage become very apparent:  Any two records with the same named
attributes of the same types are always of the same type.  In PostgreSQL,
this would mean that functions that operate on RECORD{x:int,y:int,s:string}
could operate on a record from any relation with those attributes.

Further, to make inheritance pretty much unnecesary, you could allow a
record with more attributes to satisfy a parameter or return value constraint.
In other words, you could call function foo(RECORD{x:int,y:int}) on a
RECORD{s:string,x:int,y:int}.

I've thought about this trick a lot.  In theory there is a possibility of
not getting what you want, but in practice it would almost never happen.  The
demostrative case would be calling distance_from_origin(RECORD{x:int,y:int})
on RECORD{x:int,y:int,z:int}, but in this case you need to make a 
distance_from_origin(RECORD{x:int,y:int,z:int}).

This way, you could make a function which operates on RECORD{oid:oid} which
could be called on any record from a table.  I've wanted to do this sort of
thing on several occasions- one application has notes which can be attached
to any row, sort of like PostgreSQL comments.  Another to keep track of what
user 

Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-10 Thread Tom Lane
Joe Conway [EMAIL PROTECTED] writes:
 So if I understand correctly, all instances of anyarray and anyelement 
 in a function definition would need to be self-consistent, but the group 
 could represent essentially any datatype with its corresponding array 
 type. If we need more than one of these self consistent groups, we could 
 resort to anyarray1/anyelement1, etc. Does this sound correct?

Right.

 Also, an implementation question: if I have a type oid for an element, 
 what is the preferred method for determining the corresponding array? 
 I'm thinking that the most efficient method might be to use the 
 element-type name with a '_' prepended to get the array-type oid, but 
 that seems ugly. Thoughts?

I was thinking about that earlier.  Right now there is no other way.
We could consider adding a column to pg_type to link to the array type,
but I'm not sure it's worth the trouble.  I think if you look around,
there's probably already a subroutine someplace that does the lookup
using the '_foo' approach.

regards, tom lane

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-10 Thread Christopher Kings-Lynne
 So if I understand correctly, all instances of anyarray and anyelement 
 in a function definition would need to be self-consistent, but the group 
 could represent essentially any datatype with its corresponding array 
 type. If we need more than one of these self consistent groups, we could 
 resort to anyarray1/anyelement1, etc. Does this sound correct?
 
 Also, an implementation question: if I have a type oid for an element, 
 what is the preferred method for determining the corresponding array? 
 I'm thinking that the most efficient method might be to use the 
 element-type name with a '_' prepended to get the array-type oid, but 
 that seems ugly. Thoughts?

What about a cast?  1::arraytype

Chris


---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-09 Thread Tom Lane
Joe Conway [EMAIL PROTECTED] writes:
 Tom Lane wrote:
 The array type is determined how?  I'd like this syntax better if there
 were a way to force the choice of array type...

 What about:
 select integer ARRAY[1,2,3];
 result '{1,2,3}'::integer[]

By analogy to the type 'literal' syntax?  I'd prefer not to go that
route, because that syntax for literals is a horrid kluge --- to keep
bison from spitting up, we've had to put a bunch of nasty restrictions
on the type names that can appear in such constructs.  All those
restrictions would have to apply here, too.

It's possible that we could use the other cast syntaxes:
ARRAY[1,2,3]::integer[]
CAST(ARRAY[1,2,3] AS integer[])
It would take some hackery to propagate the destination type down into
the ARRAY[] before the latter's type resolution is done, but at least
it'd be a quite localized hack.

 Puh-leez tell me that's not in the spec.  How is one supposed to
 distinguish this usage from the scalar-subselect case?

 but SQL200x has this:

 array value constructor ::=
array value constructor by enumeration |
array value constructor by query
 array value constructor by enumeration ::=
ARRAY left bracket or trigraph
  array element list
  right bracket or trigraph
 array value constructor by query ::=
ARRAY left paren
  query expression [ order by clause ]
  right paren

This I could live with --- note the difference in punctuation.  There
would be a clear syntactic and semantic difference between
ARRAY(SELECT ...) and ARRAY[(SELECT ...)].

 How many variants of the || operator do you plan to offer?

 One for each builtin datatype[]/datatype pair (e.g. integer[]/integer), 
 and another for each datatype[] (e.g. integer[]/integer[])

That does not seem workable at all.  It'll be a maintenance nightmare
even worse than what we already have for array equality; and I suspect
you'll find that the parser will have trouble resolving which || to pick.

I have been toying with the idea of replacing all the array-equality
operators with a single pg_proc/pg_operator entry for ANYARRAY = ANYARRAY.
Now that arrays carry their element type in the header, a single
function could implement all these variants.  Type mismatch (eg,
int[] = float[]) would become a runtime error instead of a parse error,
but that seems acceptable.

I see how the array || array cases could be handled similarly, but I
don't see how to make array || scalar work that way.  If we declared an
operator ANYARRAY || ANY then there'd be no way for it to check at
runtime that the right-hand operand matched the lefthand element type.
(Also, it'd create resolution conflicts with ANYARRAY || ANYARRAY.)

It'd be nice to have a general-purpose solution for this problem.
If we did, the stuff in contrib/array would benefit too, and perhaps
have (at last) a shot at becoming mainstream.

Speculating wildly: what if we invent a new pseudotype ANYARRAYELEMENT,
which would be allowed only in operator/function declarations that also
use ANYARRAY, eg
ANYARRAY || ANYARRAYELEMENT
and would match only the element type of the array in the ANYARRAY
position.  I think it'd be possible to hack the parser to make such a
check in parse_coerce.  There might be a cleaner way to do this, but
I do feel that something along this line is a better approach than
creating N different pg_operator entries for the same operation.

regards, tom lane

---(end of broadcast)---
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-09 Thread Joe Conway
Tom Lane wrote:
By analogy to the type 'literal' syntax?  I'd prefer not to go that
route, because that syntax for literals is a horrid kluge --- to keep
bison from spitting up, we've had to put a bunch of nasty restrictions
on the type names that can appear in such constructs.  All those
restrictions would have to apply here, too.
It's possible that we could use the other cast syntaxes:
ARRAY[1,2,3]::integer[]
CAST(ARRAY[1,2,3] AS integer[])
It would take some hackery to propagate the destination type down into
the ARRAY[] before the latter's type resolution is done, but at least
it'd be a quite localized hack.
OK -- I'll try to make that work. I presume that in the non-specified 
case ARRAY[1,2,3] I should use something similar to UNION's resolution 
rules?

array value constructor by enumeration ::=
  ARRAY left bracket or trigraph
array element list
right bracket or trigraph
array value constructor by query ::=
  ARRAY left paren
query expression [ order by clause ]
right paren
This I could live with --- note the difference in punctuation.  There
would be a clear syntactic and semantic difference between
ARRAY(SELECT ...) and ARRAY[(SELECT ...)].
Sorry -- I guess I mis-read that. So ARRAY(SELECT ...) it is.

 [...lots of good ideas regarding generalizing array operations...]

I played with generalizing array functions a bit for plr and ran into 
some problems (which I can't specifically recall at the moment), but 
clearly that's the way to go. I'll start playing with your suggestions 
in C code, and report back for more feedback as it solidifies.

Thanks!

Joe



---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
   (send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-09 Thread Tom Lane
Joe Conway [EMAIL PROTECTED] writes:
 Tom Lane wrote:
 It would take some hackery to propagate the destination type down into
 the ARRAY[] before the latter's type resolution is done, but at least
 it'd be a quite localized hack.

 OK -- I'll try to make that work. I presume that in the non-specified 
 case ARRAY[1,2,3] I should use something similar to UNION's resolution 
 rules?

Yeah, that'd make sense to me.

 [...lots of good ideas regarding generalizing array operations...]

 I played with generalizing array functions a bit for plr and ran into 
 some problems (which I can't specifically recall at the moment), but 
 clearly that's the way to go. I'll start playing with your suggestions 
 in C code, and report back for more feedback as it solidifies.

It'd be useful if you can reconstruct what problems you ran into.


After more thought I'm thinking that we should specify these pseudotypes
like so: a given set of actual operand types matches an
operator/function whose definition uses ANYARRAY or ANYELEMENT only if
the same element type is involved at all positions.  Thus in
ANYARRAY = ANYARRAY
the left and right operands must be the same array type (so we preserve
the existing parse-time check, but we only need one pg_operator entry
to do it).  For
ANYARRAY || ANYELEMENT
we get the desired behavior.  And there are some other interesting
possibilities: for example, a function could be declared
foo(ANY, ANYELEMENT, ANYELEMENT)
which would mean that it takes any three datatypes, but the second
and third arguments have to be the same datatype.

If we run into limitations of this scheme, it could be generalized
further by adding pseudotypes ANYARRAY2 and ANYELEMENT2 that have
the same restriction among themselves, but are independent of
ANYARRAY/ANYELEMENT.  Then for example
foo(ANYELEMENT, ANYELEMENT, ANYELEMENT2, ANYELEMENT2)
takes four params that can be anything so long as the first two are
the same datatype and the second two are also the same datatype (but
possibly a different type from the first two).  And you could add
ANYARRAY3, etc, till you got bored.  But I'd not bother with this
until someone showed a concrete need for it.  At the moment, the
useful examples I can think of don't need more than one free variable
in their set of argument datatypes.

regards, tom lane

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-09 Thread Joe Conway
Tom Lane wrote:
I played with generalizing array functions a bit for plr and ran into 
some problems (which I can't specifically recall at the moment), but 
clearly that's the way to go. I'll start playing with your suggestions 
in C code, and report back for more feedback as it solidifies.
It'd be useful if you can reconstruct what problems you ran into.

I've played around a bit more and refreshed my memory -- here are two 
problems:

CREATE OR REPLACE FUNCTION array_push (anyarray, any)
RETURNS anyarray
AS '$libdir/plr','array_push'
LANGUAGE 'C';
ERROR:  parser: parse error at or near any at character 50
It seems that any is not accepted as a function parameter type. From 
gram.y it appears that the cause is that any is a reserved keyword:

snip
/*
 * Name classification hierarchy.
 *
 * IDENT is the lexeme returned by the lexer for identifiers that match
 * no known keyword.  In most cases, we can accept certain keywords as
/snip
snip
/* Type identifier --- names that can be type names.
 */
type_name:  IDENT   { $$ = $1; }
| unreserved_keyword { $$ = pstrdup($1); }
;
/snip
So for grins I did this:
regression=# select oid,typname from pg_type where typname like '%any%';
 oid  | typname
--+--
 2276 | any
 2277 | anyarray
(2 rows)
regression=# update pg_type set typname = 'anyscalar' where oid = 2276;
UPDATE 1
CREATE OR REPLACE FUNCTION array_push (anyarray, anyscalar)
RETURNS anyarray
AS '$libdir/plr','array_push'
LANGUAGE 'C';
regression=# select array_push('{1,2}'::integer[],3::integer);
 array_push

 {1,2,3}
(1 row)
So far, so good. But now the second problem:
select f1[2] from
   (select array_push('{1,2}'::integer[],3::integer) as f1) as t;
ERROR:  transformArraySubscripts: type anyarray is not an array
I'm just starting to dig into this one.

Joe

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-09 Thread Tom Lane
Joe Conway [EMAIL PROTECTED] writes:
 It seems that any is not accepted as a function parameter type.

You have to double-quote it.

We could perhaps rename it to avoid the keyword conflict; I'd lean
towards anytype if we do (anyscalar seems misleading; I'd expect
that to exclude arrays).  I think I chose ANY because there was
precedent in CREATE AGGREGATE for that.

 So far, so good. But now the second problem:
 select f1[2] from
 (select array_push('{1,2}'::integer[],3::integer) as f1) as t;
 ERROR:  transformArraySubscripts: type anyarray is not an array

Mph.  I'm not sure we can make that work readily ... unless you want
to make the parser assume that a function taking and returning ANYARRAY
actually returns the same array type as its input is.  Otherwise the
parser has no way to determine the datatype yielded by f1[2].

regards, tom lane

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-09 Thread Hannu Krosing
Joe Conway kirjutas E, 10.03.2003 kell 05:35:

 CREATE OR REPLACE FUNCTION array_push (anyarray, anyscalar)
 RETURNS anyarray
 AS '$libdir/plr','array_push'
 LANGUAGE 'C';

could you make it

RETURNS typeof($1)


?

--
Hannu


---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])


[HACKERS] SQL99 ARRAY support proposal

2003-03-08 Thread Joe Conway
I'd like to implement SQL99/200x ARRAY support (well, at least the 
basics). Does anyone have objections to the following grammar/semantics?

===
Per SQL200x - examples
===
create table foo(f1 integer ARRAY[3]);
  result same as create table foo(f1 integer[3]); the 3
  really does nothing (this deviates from spec but is
  same as current implementation)
create table foo(f1 integer ARRAY);
  result same as create table foo(f1 integer[]);
select ARRAY[1,2,3];
  result '{1,2,3}'
select ARRAY[(select oid from pg_class order by relname)];
  result is array of all the oid's in pg_class in relname order
select ARRAY[1,2] || 3
  result '{1,2,3}'
select ARRAY[1,2] || ARRAY[3,4]
  result '{1,2,3,4}'
===
Proposed PostgreSQL extensions
===
select ARRAY[[1,2,3], [4,5,6]];
  result '{{1,2,3},{4,5,6}}'
select ARRAY[[1,2],[3,4]] || 5
  result '{{1},{3},{5}}'
select ARRAY[[1,2],[3,4]] || [5,6]
  result '{{1,2},{3,4},{5,6}}'
use UNION's algorithm for deriving the element type when not specified
Comments, suggestions, objections?

Thanks,

Joe

---(end of broadcast)---
TIP 6: Have you searched our list archives?
http://archives.postgresql.org


Re: [HACKERS] SQL99 ARRAY support proposal

2003-03-08 Thread Tom Lane
Joe Conway [EMAIL PROTECTED] writes:
 select ARRAY[1,2,3];
result '{1,2,3}'

The array type is determined how?  I'd like this syntax better if there
were a way to force the choice of array type...

 select ARRAY[(select oid from pg_class order by relname)];
result is array of all the oid's in pg_class in relname order

Puh-leez tell me that's not in the spec.  How is one supposed to
distinguish this usage from the scalar-subselect case?

 select ARRAY[1,2] || 3
result '{1,2,3}'

Datatypes?  How many variants of the || operator do you plan to offer?
What will be the side-effects on the parser's ability to pick one?

 select ARRAY[1,2] || ARRAY[3,4]
result '{1,2,3,4}'

Same worry as above; likewise for the proposed extensions.

regards, tom lane

---(end of broadcast)---
TIP 6: Have you searched our list archives?

http://archives.postgresql.org