public inbox for [email protected]  
help / color / mirror / Atom feed
Array function
13+ messages / 5 participants
[nested] [flat]

* Array function
@ 2004-11-01 00:36  David Fetter <[email protected]>
  0 siblings, 2 replies; 13+ messages in thread

From: David Fetter @ 2004-11-01 00:36 UTC (permalink / raw)
  To: pgsql-docs

Folks,

Here's a little addition to the array functions & operators section of
the manual.  It adds a function array() to the list.

Cheers,
D
-- 
David Fetter [email protected] http://fetter.org/
phone: +1 510 893 6100   mobile: +1 415 235 3778

Remember to vote!

Index: doc/src/sgml/func.sgml
===================================================================
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/func.sgml,v
retrieving revision 1.221
diff -u -r1.221 func.sgml
--- doc/src/sgml/func.sgml	26 Oct 2004 22:16:11 -0000	1.221
+++ doc/src/sgml/func.sgml	1 Nov 2004 00:33:22 -0000
@@ -6928,6 +6928,20 @@
 	<entry><literal>string_to_array( 'xx~^~yy~^~zz', '~^~')</literal></entry>
 	<entry><literal>{xx,yy,zz}</literal></entry>
        </row>
+       <row>
+	<entry>
+     <literal>
+      <function>array</function>
+      (single-column SELECT)
+     </literal>
+    </entry>
+	<entry><type>anyarray</type></entry>
+    <entry>
+     turns a single-column <literal>SELECT</literal> statement into an array
+    </entry>
+    <entry><literal>array(SELECT foo FROM bar)</literal></entry>
+    <entry><literal>{1,2,3}</literal></entry>
+       </row>
       </tbody>
      </tgroup>
     </table>


Attachments:

  [text/plain] array_func.diff (936B, 2-array_func.diff)
  download | inline diff:
Index: doc/src/sgml/func.sgml
===================================================================
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/func.sgml,v
retrieving revision 1.221
diff -u -r1.221 func.sgml
--- doc/src/sgml/func.sgml	26 Oct 2004 22:16:11 -0000	1.221
+++ doc/src/sgml/func.sgml	1 Nov 2004 00:33:22 -0000
@@ -6928,6 +6928,20 @@
 	<entry><literal>string_to_array( 'xx~^~yy~^~zz', '~^~')</literal></entry>
 	<entry><literal>{xx,yy,zz}</literal></entry>
        </row>
+       <row>
+	<entry>
+     <literal>
+      <function>array</function>
+      (single-column SELECT)
+     </literal>
+    </entry>
+	<entry><type>anyarray</type></entry>
+    <entry>
+     turns a single-column <literal>SELECT</literal> statement into an array
+    </entry>
+    <entry><literal>array(SELECT foo FROM bar)</literal></entry>
+    <entry><literal>{1,2,3}</literal></entry>
+       </row>
       </tbody>
      </tgroup>
     </table>


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

* Re: Array function
@ 2004-11-01 03:40  Tom Lane <[email protected]>
  parent: David Fetter <[email protected]>
  1 sibling, 1 reply; 13+ messages in thread

From: Tom Lane @ 2004-11-01 03:40 UTC (permalink / raw)
  To: David Fetter <[email protected]>; +Cc: pgsql-docs

David Fetter <[email protected]> writes:
> Here's a little addition to the array functions & operators section of
> the manual.  It adds a function array() to the list.

The ARRAY() construct isn't really a function; it is a special syntax
documented in Array Constructors,
http://developer.postgresql.org/docs/postgres/sql-expressions.html#SQL-SYNTAX-ARRAY-CONSTRUCTORS

The addition you propose is misleading, because it would lead people to
expect to find array() in the output of \df, for example.  It might be
reasonable to put in some kind of "see also" cross-reference in the
array functions section, but we shouldn't list array() as though it were
just like every other function in the section.

			regards, tom lane



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

* Re: Array function
@ 2004-11-01 05:21  David Fetter <[email protected]>
  parent: Tom Lane <[email protected]>
  0 siblings, 1 reply; 13+ messages in thread

From: David Fetter @ 2004-11-01 05:21 UTC (permalink / raw)
  To: Tom Lane <[email protected]>; +Cc: pgsql-docs

On Sun, Oct 31, 2004 at 10:40:47PM -0500, Tom Lane wrote:
> David Fetter <[email protected]> writes:
> > Here's a little addition to the array functions & operators section of
> > the manual.  It adds a function array() to the list.
> 
> The ARRAY() construct isn't really a function; it is a special
> syntax documented in Array Constructors,
> http://developer.postgresql.org/docs/postgres/sql-expressions.html#SQL-SYNTAX-ARRAY-CONSTRUCTORS
> 
> The addition you propose is misleading, because it would lead people
> to expect to find array() in the output of \df, for example.  It
> might be reasonable to put in some kind of "see also"
> cross-reference in the array functions section, but we shouldn't
> list array() as though it were just like every other function in the
> section.

Good point.

Please find attached a different diff :)

Cheers,
D
-- 
David Fetter [email protected] http://fetter.org/
phone: +1 510 893 6100   mobile: +1 415 235 3778

Remember to vote!

Index: doc/src/sgml/func.sgml
===================================================================
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/func.sgml,v
retrieving revision 1.221
diff -u -r1.221 func.sgml
--- doc/src/sgml/func.sgml      26 Oct 2004 22:16:11 -0000      1.221
+++ doc/src/sgml/func.sgml      1 Nov 2004 05:19:02 -0000
@@ -6931,6 +6931,16 @@
       </tbody>
      </tgroup>
     </table>
+  <para>
+  <emphasis role="bold">NOTE:</emphasis>  Although it is not strictly a function
+    and does not appear in \df in psql, <command>ARRAY()</command>,
+    mentioned in <xref linkend="sql-syntax-array-constructors"> acts much
+    like a <literal>table function</literal> (equivalently, a
+    <literal>set-returning function</literal> or a
+    <acronym>SRF</acronym>--see <xref linkend="queries-tablefunctions">)
+    which takes <type>anyarray</type> and returns a set of
+    <type>anyelement</type>.
+  </para>
   </sect1>
  
  <sect1 id="functions-aggregate">


Attachments:

  [text/plain] array.diff (982B, 2-array.diff)
  download | inline diff:
Index: doc/src/sgml/func.sgml
===================================================================
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/func.sgml,v
retrieving revision 1.221
diff -u -r1.221 func.sgml
--- doc/src/sgml/func.sgml      26 Oct 2004 22:16:11 -0000      1.221
+++ doc/src/sgml/func.sgml      1 Nov 2004 05:19:02 -0000
@@ -6931,6 +6931,16 @@
       </tbody>
      </tgroup>
     </table>
+  <para>
+  <emphasis role="bold">NOTE:</emphasis>  Although it is not strictly a function
+    and does not appear in \df in psql, <command>ARRAY()</command>,
+    mentioned in <xref linkend="sql-syntax-array-constructors"> acts much
+    like a <literal>table function</literal> (equivalently, a
+    <literal>set-returning function</literal> or a
+    <acronym>SRF</acronym>--see <xref linkend="queries-tablefunctions">)
+    which takes <type>anyarray</type> and returns a set of
+    <type>anyelement</type>.
+  </para>
   </sect1>
  
  <sect1 id="functions-aggregate">


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

* Re: Array function
@ 2004-11-01 19:47  Peter Eisentraut <[email protected]>
  parent: David Fetter <[email protected]>
  0 siblings, 1 reply; 13+ messages in thread

From: Peter Eisentraut @ 2004-11-01 19:47 UTC (permalink / raw)
  To: David Fetter <[email protected]>; Tom Lane <[email protected]>; +Cc: pgsql-docs

David Fetter wrote:
> Please find attached a different diff :)

If you want to write a note, use the <note> element.

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/




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

* Re: Array function
@ 2004-11-01 19:59  Jim C. Nasby <[email protected]>
  parent: David Fetter <[email protected]>
  1 sibling, 1 reply; 13+ messages in thread

From: Jim C. Nasby @ 2004-11-01 19:59 UTC (permalink / raw)
  To: David Fetter <[email protected]>; +Cc: pgsql-docs

BTW, it seems it would be useful to dedicate a chapter to array
handling, since it's something that's not very common amongst databases.

On Sun, Oct 31, 2004 at 04:36:14PM -0800, David Fetter wrote:
> Folks,
> 
> Here's a little addition to the array functions & operators section of
> the manual.  It adds a function array() to the list.
> 
> Cheers,
> D
-- 
Jim C. Nasby, Database Consultant               [email protected] 
Give your computer some brain candy! www.distributed.net Team #1828

Windows: "Where do you want to go today?"
Linux: "Where do you want to go tomorrow?"
FreeBSD: "Are you guys coming, or what?"



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

* Re: Array function
@ 2004-11-01 20:21  David Fetter <[email protected]>
  parent: Peter Eisentraut <[email protected]>
  0 siblings, 2 replies; 13+ messages in thread

From: David Fetter @ 2004-11-01 20:21 UTC (permalink / raw)
  To: Peter Eisentraut <[email protected]>; +Cc: Tom Lane <[email protected]>; pgsql-docs

On Mon, Nov 01, 2004 at 08:47:05PM +0100, Peter Eisentraut wrote:
> David Fetter wrote:
> > Please find attached a different diff :)
> 
> If you want to write a note, use the <note> element.

Thanks for the tip :)

Fixed, attaching a diff against CVS HEAD.

Cheers,
D
-- 
David Fetter [email protected] http://fetter.org/
phone: +1 510 893 6100   mobile: +1 415 235 3778

Remember to vote!

Index: doc/src/sgml/func.sgml
===================================================================
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/func.sgml,v
retrieving revision 1.221
diff -u -r1.221 func.sgml
--- doc/src/sgml/func.sgml	26 Oct 2004 22:16:11 -0000	1.221
+++ doc/src/sgml/func.sgml	1 Nov 2004 20:21:02 -0000
@@ -6931,6 +6931,18 @@
       </tbody>
      </tgroup>
     </table>
+  <note>
+  <para>
+    Although it is not strictly a function and does not appear in \df
+    in psql, <command>ARRAY()</command>, mentioned in <xref
+    linkend="sql-syntax-array-constructors"> acts much like a
+    <literal>table function</literal> (equivalently, a
+    <literal>set-returning function</literal> or a
+    <acronym>SRF</acronym>--see <xref linkend="queries-tablefunctions">)
+    which takes <type>anyarray</type> and returns a set of
+    <type>anyelement</type>.
+  </para>
+  </note>
   </sect1>
 
  <sect1 id="functions-aggregate">


Attachments:

  [text/plain] array.diff (949B, 2-array.diff)
  download | inline diff:
Index: doc/src/sgml/func.sgml
===================================================================
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/func.sgml,v
retrieving revision 1.221
diff -u -r1.221 func.sgml
--- doc/src/sgml/func.sgml	26 Oct 2004 22:16:11 -0000	1.221
+++ doc/src/sgml/func.sgml	1 Nov 2004 20:21:02 -0000
@@ -6931,6 +6931,18 @@
       </tbody>
      </tgroup>
     </table>
+  <note>
+  <para>
+    Although it is not strictly a function and does not appear in \df
+    in psql, <command>ARRAY()</command>, mentioned in <xref
+    linkend="sql-syntax-array-constructors"> acts much like a
+    <literal>table function</literal> (equivalently, a
+    <literal>set-returning function</literal> or a
+    <acronym>SRF</acronym>--see <xref linkend="queries-tablefunctions">)
+    which takes <type>anyarray</type> and returns a set of
+    <type>anyelement</type>.
+  </para>
+  </note>
   </sect1>
 
  <sect1 id="functions-aggregate">


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

* Re: Array function
@ 2004-11-01 20:38  David Fetter <[email protected]>
  parent: Jim C. Nasby <[email protected]>
  0 siblings, 2 replies; 13+ messages in thread

From: David Fetter @ 2004-11-01 20:38 UTC (permalink / raw)
  To: Jim C. Nasby <[email protected]>; +Cc: pgsql-docs

On Mon, Nov 01, 2004 at 01:59:13PM -0600, Jim C. Nasby wrote:
> On Sun, Oct 31, 2004 at 04:36:14PM -0800, David Fetter wrote:
> > Folks,
> > 
> > Here's a little addition to the array functions & operators
> > section of the manual.  It adds a function array() to the list.
> > 
> > Cheers, D
>
> BTW, it seems it would be useful to dedicate a chapter to array
> handling, since it's something that's not very common amongst
> databases.

I guess it depends what you mean. Oracle has "subtables," and other
things have stuff like that.  Also, it's in the SQL standard...

Anyhow, where do you think it should go?

Cheers,
D
-- 
David Fetter [email protected] http://fetter.org/
phone: +1 510 893 6100   mobile: +1 415 235 3778

Remember to vote!



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

* Re: Array function
@ 2004-11-01 22:11  Peter Eisentraut <[email protected]>
  parent: David Fetter <[email protected]>
  1 sibling, 1 reply; 13+ messages in thread

From: Peter Eisentraut @ 2004-11-01 22:11 UTC (permalink / raw)
  To: David Fetter <[email protected]>; Jim C. Nasby <[email protected]>; +Cc: pgsql-docs

David Fetter wrote:
> Anyhow, where do you think it should go?

In the chapter on data types -- where it already is.

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/




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

* Re: Array function
@ 2004-11-02 20:43  Jim C. Nasby <[email protected]>
  parent: Peter Eisentraut <[email protected]>
  0 siblings, 1 reply; 13+ messages in thread

From: Jim C. Nasby @ 2004-11-02 20:43 UTC (permalink / raw)
  To: Peter Eisentraut <[email protected]>; +Cc: David Fetter <[email protected]>; pgsql-docs

The datatypes chapter mentions nothing about ARRAY(), for starters. I'm
not suggesting that the reference is incomplete, but I think a chapter
explaining some about arrays, how to use them, and what you can do with
them would be useful.

On Mon, Nov 01, 2004 at 11:11:31PM +0100, Peter Eisentraut wrote:
> David Fetter wrote:
> > Anyhow, where do you think it should go?
> 
> In the chapter on data types -- where it already is.
> 
> -- 
> Peter Eisentraut
> http://developer.postgresql.org/~petere/
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to [email protected]
> 

-- 
Jim C. Nasby, Database Consultant               [email protected] 
Give your computer some brain candy! www.distributed.net Team #1828

Windows: "Where do you want to go today?"
Linux: "Where do you want to go tomorrow?"
FreeBSD: "Are you guys coming, or what?"



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

* Re: Array function
@ 2004-11-02 23:31  Jim C. Nasby <[email protected]>
  parent: Jim C. Nasby <[email protected]>
  0 siblings, 0 replies; 13+ messages in thread

From: Jim C. Nasby @ 2004-11-02 23:31 UTC (permalink / raw)
  To: Peter Eisentraut <[email protected]>; +Cc: David Fetter <[email protected]>; pgsql-docs

Here's an example I just thought of that would be great to document:

I have an array of integers. I'd like to also associate some names with
them. I can't do this in the same array, but I can do it in a different
array. But how do I ensure that when I build that array using
name=ARRAY(SELECT name FROM table WHERE id = ANY(id_array) ) that name[1]
actually corresponds to id_array[1]?

On Tue, Nov 02, 2004 at 02:43:42PM -0600, Jim C. Nasby wrote:
> The datatypes chapter mentions nothing about ARRAY(), for starters. I'm
> not suggesting that the reference is incomplete, but I think a chapter
> explaining some about arrays, how to use them, and what you can do with
> them would be useful.
> 
> On Mon, Nov 01, 2004 at 11:11:31PM +0100, Peter Eisentraut wrote:
> > David Fetter wrote:
> > > Anyhow, where do you think it should go?
> > 
> > In the chapter on data types -- where it already is.
> > 
> > -- 
> > Peter Eisentraut
> > http://developer.postgresql.org/~petere/
> > 
> > 
> > ---------------------------(end of broadcast)---------------------------
> > TIP 1: subscribe and unsubscribe commands go to [email protected]
> > 
> 
> -- 
> Jim C. Nasby, Database Consultant               [email protected] 
> Give your computer some brain candy! www.distributed.net Team #1828
> 
> Windows: "Where do you want to go today?"
> Linux: "Where do you want to go tomorrow?"
> FreeBSD: "Are you guys coming, or what?"
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
> 
>                http://archives.postgresql.org
> 

-- 
Jim C. Nasby, Database Consultant               [email protected] 
Give your computer some brain candy! www.distributed.net Team #1828

Windows: "Where do you want to go today?"
Linux: "Where do you want to go tomorrow?"
FreeBSD: "Are you guys coming, or what?"



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

* Re: Array function
@ 2004-11-28 04:06  Bruce Momjian <[email protected]>
  parent: David Fetter <[email protected]>
  1 sibling, 0 replies; 13+ messages in thread

From: Bruce Momjian @ 2004-11-28 04:06 UTC (permalink / raw)
  To: David Fetter <[email protected]>; +Cc: Peter Eisentraut <[email protected]>; Tom Lane <[email protected]>; pgsql-docs


Your patch has been added to the PostgreSQL unapplied patches list at:

	http://momjian.postgresql.org/cgi-bin/pgpatches

It will be applied as soon as one of the PostgreSQL committers reviews
and approves it.

---------------------------------------------------------------------------


David Fetter wrote:
> On Mon, Nov 01, 2004 at 08:47:05PM +0100, Peter Eisentraut wrote:
> > David Fetter wrote:
> > > Please find attached a different diff :)
> > 
> > If you want to write a note, use the <note> element.
> 
> Thanks for the tip :)
> 
> Fixed, attaching a diff against CVS HEAD.
> 
> Cheers,
> D
> -- 
> David Fetter [email protected] http://fetter.org/
> phone: +1 510 893 6100   mobile: +1 415 235 3778
> 
> Remember to vote!

[ Attachment, skipping... ]

> 
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  [email protected]               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073



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

* Re: Array function
@ 2004-11-28 04:08  Bruce Momjian <[email protected]>
  parent: David Fetter <[email protected]>
  1 sibling, 0 replies; 13+ messages in thread

From: Bruce Momjian @ 2004-11-28 04:08 UTC (permalink / raw)
  To: David Fetter <[email protected]>; +Cc: Jim C. Nasby <[email protected]>; pgsql-docs


FYI, this discussion about adding a separate array section to the docs
(which we already have, as Peter pointed out) is independent of the
ARRAY() documentation addition I just put in the patch queue.

---------------------------------------------------------------------------

David Fetter wrote:
> On Mon, Nov 01, 2004 at 01:59:13PM -0600, Jim C. Nasby wrote:
> > On Sun, Oct 31, 2004 at 04:36:14PM -0800, David Fetter wrote:
> > > Folks,
> > > 
> > > Here's a little addition to the array functions & operators
> > > section of the manual.  It adds a function array() to the list.
> > > 
> > > Cheers, D
> >
> > BTW, it seems it would be useful to dedicate a chapter to array
> > handling, since it's something that's not very common amongst
> > databases.
> 
> I guess it depends what you mean. Oracle has "subtables," and other
> things have stuff like that.  Also, it's in the SQL standard...
> 
> Anyhow, where do you think it should go?
> 
> Cheers,
> D
> -- 
> David Fetter [email protected] http://fetter.org/
> phone: +1 510 893 6100   mobile: +1 415 235 3778
> 
> Remember to vote!
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
>       joining column's datatypes do not match
> 

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  [email protected]               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073



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

* Re: Array function
@ 2004-12-02 21:04  Bruce Momjian <[email protected]>
  parent: David Fetter <[email protected]>
  1 sibling, 0 replies; 13+ messages in thread

From: Bruce Momjian @ 2004-12-02 21:04 UTC (permalink / raw)
  To: David Fetter <[email protected]>; +Cc: Peter Eisentraut <[email protected]>; Tom Lane <[email protected]>; pgsql-docs


Patch applied.  Thanks.

---------------------------------------------------------------------------


David Fetter wrote:
> On Mon, Nov 01, 2004 at 08:47:05PM +0100, Peter Eisentraut wrote:
> > David Fetter wrote:
> > > Please find attached a different diff :)
> > 
> > If you want to write a note, use the <note> element.
> 
> Thanks for the tip :)
> 
> Fixed, attaching a diff against CVS HEAD.
> 
> Cheers,
> D
> -- 
> David Fetter [email protected] http://fetter.org/
> phone: +1 510 893 6100   mobile: +1 415 235 3778
> 
> Remember to vote!

[ Attachment, skipping... ]

> 
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  [email protected]               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073




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


end of thread, other threads:[~2004-12-02 21:04 UTC | newest]

Thread overview: 13+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-11-01 00:36 Array function David Fetter <[email protected]>
2004-11-01 03:40 ` Tom Lane <[email protected]>
2004-11-01 05:21   ` David Fetter <[email protected]>
2004-11-01 19:47     ` Peter Eisentraut <[email protected]>
2004-11-01 20:21       ` David Fetter <[email protected]>
2004-11-28 04:06         ` Bruce Momjian <[email protected]>
2004-12-02 21:04         ` Bruce Momjian <[email protected]>
2004-11-01 19:59 ` Jim C. Nasby <[email protected]>
2004-11-01 20:38   ` David Fetter <[email protected]>
2004-11-01 22:11     ` Peter Eisentraut <[email protected]>
2004-11-02 20:43       ` Jim C. Nasby <[email protected]>
2004-11-02 23:31         ` Jim C. Nasby <[email protected]>
2004-11-28 04:08     ` Bruce Momjian <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox