Home > Archive > PostgreSQL Discussion > April 2006 > Re: sort a referenced list









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: sort a referenced list
Matthew Peter

2006-04-04, 3:27 am

I'll help clarify exactly what I am trying to accomplish.

What I'm trying to do is create a function that accepts a list then sorts and groups the values (like in sql)... I will have an unique list I can convert it to an array later or leave it a list

I'd like to keep it simple and manipulate the argument like...

select $1 as list
group by list
order by list asc;

Which doesn't work, but that is the functionality I need if possible.



---------------------------------
New Yahoo! Messenger with Voice. Call regular phones from your PC for low, low rates.
Tom Lane

2006-04-04, 9:28 am

Matthew Peter <survivedsushi@yahoo.com> writes:
> What I'm trying to do is create a function that accepts a list then sorts and groups the values (like in sql)... I will have an unique list I can convert it to an array later or leave it a list


There is no "list" data structure in SQL. There are tables, and there
are arrays, but it's not especially easy to pass an arbitrary table
value to a function. So you almost certainly need to define your
problem as "create a function that accepts an array then ...".

regards, tom lane

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

http://archives.postgresql.org

Matthew Peter

2006-04-04, 8:26 pm



Tom Lane <tgl@sss.pgh.pa.us> wrote: Matthew Peter writes:
> What I'm trying to do is create a function that accepts a list then sorts and groups the values (like in sql)... I will have an unique list I can convert it to an array later or leave it a list


There is no "list" data structure in SQL. There are tables, and there
are arrays, but it's not especially easy to pass an arbitrary table
value to a function. So you almost certainly need to define your
problem as "create a function that accepts an array then ...".

regards, tom lane

Originally I wanted to pass in text or varchar array, group it, sort it then do as I willed with it, but I couldn't figure out how. I saw some functions in the contrib for doing these operations, yet only with integer arrays.

I could always try converting the array_sort, array_uniq int[] C function to accept text[], but I decided to ask and see if there was a simplier/standard way first since I don't know C all that well.

Thanks


---------------------------------
Blab-away for as little as 1¢/min. Make PC-to-Phone Calls using Yahoo! Messenger with Voice.
Jim Nasby

2006-04-07, 3:36 am

On Apr 4, 2006, at 3:22 PM, Matthew Peter wrote:
> Tom Lane <tgl@sss.pgh.pa.us> wrote: Matthew Peter writes:
> then sorts and groups the values (like in sql)... I will have an
> unique list I can convert it to an array later or leave it a list
>
> There is no "list" data structure in SQL. There are tables, and there
> are arrays, but it's not especially easy to pass an arbitrary table
> value to a function. So you almost certainly need to define your
> problem as "create a function that accepts an array then ...".
>
> regards, tom lane
>
> Originally I wanted to pass in text or varchar array, group it,
> sort it then do as I willed with it, but I couldn't figure out how.
> I saw some functions in the contrib for doing these operations, yet
> only with integer arrays.
>
> I could always try converting the array_sort, array_uniq int[] C
> function to accept text[], but I decided to ask and see if there
> was a simplier/standard way first since I don't know C all that well.


Sadly there's very little in the way of array operators in
PostgreSQL, so your best bet would be to modify what's in contrib,
preferably allowing it to work with any data type. I'm guessing that
the int array stuff is in contrib and not in the backend because
we're waiting for someone to make it work for all types...
--
Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461



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

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com