Re: [SQL] Existential quantifier

2009-10-09 Thread Richard Albright
you could use distinct on select distinct on (fs.film.title, fs.film.year ) title, year from fs.film left join fs.star on fs.film.id = fs.star.film where fs.star.last = 'Sheen'; On Sat, 2009-10-10 at 00:53 +0200, Dag-Erling Smørgrav wrote: > Consider the attached schema (filmstars.sql), which i

Re: [SQL] pl/python out params

2010-08-07 Thread Richard Albright
first define a custom type, then drop the out parameters. create type mytype as ( i integer, j text ); create or replace function outtest() returns mytype as $BODY$ i = 1 j = 'something' return ( i, j ) $BODY$ language plpythonu; select * from outtest(); i | j ---+--- 1 | someth

Re: [SQL]How to transform table rows into Colum?

2011-03-17 Thread Richard Albright
you can also generate a crosstab table using the sign function you can check out the link below ( its a sqlite tutorial, but the same idea will work for pg too ) http://souptonuts.sourceforge.net/readme_sqlite_tutorial.html On 03/09/2011 12:16 PM, Eric Ndengang wrote: Hi Guys, I have the fo

[SQL] plpgsql array looping

2007-04-24 Thread Richard Albright
I am attempting to create a moving average elements function that will return a set of elements in a particular moving average and am having difficulty iterating thrrough the passed in array properly. Any help would be greatly appreciated. code below... select getmovavgelements( aggarray(trade_d

Re: [SQL] plpgsql array looping

2007-04-25 Thread Richard Albright
ent) > is that you are incrementing idxptr explicitly in your loop. The FOR > loop does that for you. This is the reason your output shows only > even values. > > John > > > On Apr 24, 2007, at 4:42 PM, Richard Albright wrote: > > > for idxptr in 1 .. arr

[SQL] sql wrapped plpgsql set returning function

2007-04-25 Thread Richard Albright
I have figured out my looping issue, but am having difficulty wrapping my set returning plpgsql function getmovavgset with a getmovavg sql func when i run the following: select getmovavg(aggarray(trade_date), aggarray(close_price), '2004-01-20', 5) from ( select trade_date, close_price::n

Re: [SQL] sql wrapped plpgsql set returning function

2007-04-25 Thread Richard Albright
gt; and trade_date > '2004-01-01' > order by trade_date desc) values whereas select * from getmovavg(array['2007-04-03', '2007-04-02', '2007-04-01']::timestamp[], array[4.0,3.0,2.0]::numeric[], '2007-04-03', 3) will work. anyon

Re: [SQL] sql wrapped plpgsql set returning function

2007-04-25 Thread Richard Albright
I narrowed it down further. Can someone explain the difference between passing array[...] and passing an array using an aggregate array function into the function? On Wed, 2007-04-25 at 14:45 -0400, Richard Albright wrote: > It turns out that the from subselect is causing the error

Re: [SQL] Possible to access value in RECORD without knowing column name?

2007-05-02 Thread Richard Albright
my_column = 'foo' sql = 'select col1, col2, ' || my_column || ' as bar from mytable; for myrecord in execute sql loop myvariable = myrecord.bar end loop; On Wed, 2007-05-02 at 12:17 -0700, Collin Peters wrote: > In plpgsl, if I have a RECORD variable that is populated via some > dynamic SQ