Re: [SQL] plpgsql out parameter with select into

2010-08-18 Thread Horváth Imre
It don't work...

Only select into status * from... works.

Imre Horvath

2010. 08. 18, szerda keltezéssel 09.42-kor Sergey Konoplev ezt írta:
> Hi,
> 
> SELECT column_name
> INTO var_name
> FROM ...
> 
> 2010/8/17 Horváth Imre :
> > Hi!
> >
> > My question is, how can I get the out parameter from a function with
> > SELECT INTO by name?
> > I mean:
> >
> > create function testfunc1(OUT _status integer) returns integer as
> > $BODY$
> >_status := 0;
> > $BODY$
> > language plpgsql;
> >
> > create function testfunc2() as
> > declare
> >status integer;
> > $BODY$
> >select into status * from testfunc1();
> > $BODY$
> > language plpgsql;
> >
> > create function testfunc3() as
> > declare
> >status integer;
> > $BODY$
> >select into status _status from testfunc1();
> > $BODY$
> > language plpgsql;
> >
> > testfunc2 works, testfunc3 not.
> >
> > Thanks in advance:
> > Imre Horvath
> >
> >
> > --
> > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> > To make changes to your subscription:
> > http://www.postgresql.org/mailpref/pgsql-sql
> >
> 
> 
> 



-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] plpgsql out parameter with select into

2010-08-18 Thread Imre Horvath
It don't work...

Only select into status * from... works.

Imre Horvath

2010. 08. 18, szerda keltezéssel 09.42-kor Sergey Konoplev ezt írta:
> Hi,
> 
> SELECT column_name
> INTO var_name
> FROM ...
> 
> 2010/8/17 Horváth Imre :
> > Hi!
> >
> > My question is, how can I get the out parameter from a function with
> > SELECT INTO by name?
> > I mean:
> >
> > create function testfunc1(OUT _status integer) returns integer as
> > $BODY$
> >_status := 0;
> > $BODY$
> > language plpgsql;
> >
> > create function testfunc2() as
> > declare
> >status integer;
> > $BODY$
> >select into status * from testfunc1();
> > $BODY$
> > language plpgsql;
> >
> > create function testfunc3() as
> > declare
> >status integer;
> > $BODY$
> >select into status _status from testfunc1();
> > $BODY$
> > language plpgsql;
> >
> > testfunc2 works, testfunc3 not.
> >
> > Thanks in advance:
> > Imre Horvath
> >
> >
> > --
> > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> > To make changes to your subscription:
> > http://www.postgresql.org/mailpref/pgsql-sql
> >
> 
> 
> 



-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] plpgsql out parameter with select into

2010-08-18 Thread Sergey Konoplev
What is your PG version?

2010/8/18 Horváth Imre :
> It don't work...
>
> Only select into status * from... works.
>
> Imre Horvath
>
> 2010. 08. 18, szerda keltezéssel 09.42-kor Sergey Konoplev ezt írta:
>> Hi,
>>
>> SELECT column_name
>> INTO var_name
>> FROM ...
>>
>> 2010/8/17 Horváth Imre :
>> > Hi!
>> >
>> > My question is, how can I get the out parameter from a function with
>> > SELECT INTO by name?
>> > I mean:
>> >
>> > create function testfunc1(OUT _status integer) returns integer as
>> > $BODY$
>> >        _status := 0;
>> > $BODY$
>> > language plpgsql;
>> >
>> > create function testfunc2() as
>> > declare
>> >        status integer;
>> > $BODY$
>> >        select into status * from testfunc1();
>> > $BODY$
>> > language plpgsql;
>> >
>> > create function testfunc3() as
>> > declare
>> >        status integer;
>> > $BODY$
>> >        select into status _status from testfunc1();
>> > $BODY$
>> > language plpgsql;
>> >
>> > testfunc2 works, testfunc3 not.
>> >
>> > Thanks in advance:
>> > Imre Horvath
>> >
>> >
>> > --
>> > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
>> > To make changes to your subscription:
>> > http://www.postgresql.org/mailpref/pgsql-sql
>> >
>>
>>
>>
>
>
>



-- 
Sergey Konoplev

Blog: http://gray-hemp.blogspot.com /
Linkedin: http://ru.linkedin.com/in/grayhemp /
JID/GTalk: gray...@gmail.com / Skype: gray-hemp / ICQ: 29353802

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] plpgsql out parameter with select into

2010-08-18 Thread Tom Lane
> 2010/8/18 Horváth Imre :
>> It don't work...

A function returning a scalar type cannot control the column name
assigned to the scalar in the calling query.  To do that, you need to
return a composite type, which means there need to be at least two OUT
parameters if you're trying to do it via OUT-parameter names.

regards, tom lane

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



[SQL] Windowed Postgres Query

2010-08-18 Thread Mindtonic
Hello.  I have a database query I am trying to develop.

For the purpose of explanation, I am going to use a suit of playing
cards in ascending order as an example.  The complete data set would
look like this:  [2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A]

The WHERE clause would contain "suit = hearts" and the ORDER would be
"value ASC".  I need to be able to page through the results, so there
should be a LIMIT.  So a basic example would be "SELECT * FROM cards
WHERE suit = hearts ORDER value LIMIT 5" and would yield [2, 3, 4, 5,
6]

I need a database query that is "windowed" around a card.  The query
would return a set of data almost identical in application to windowed
pagination links.

If the targeted number is in the middle of the set, the query should
return the number with 2 records on either side of it:

Requesting 5 => [3, 4, 5, 6, 7]
Requesting 7 => [5, 6, 7, 8, 9]

If it is near the beginning or the ending, it should return the number
and as many additional records on either side so that the total number
of records is 5.

Requesting 2 => [2, 3, 4, 5, 6]
Requesting K => [10, J, Q, K, A]

If this query is run against a set with less than 5 records, it
returns all 5 records.

What function, approach or theory should I utilize to accomplish
this?  What would the query look like?

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] plpgsql out parameter with select into

2010-08-18 Thread Sergey Konoplev
2010/8/19 Tom Lane :
>> 2010/8/18 Horváth Imre :
>>> It don't work...
>
> A function returning a scalar type cannot control the column name
> assigned to the scalar in the calling query.  To do that, you need to
> return a composite type, which means there need to be at least two OUT
> parameters if you're trying to do it via OUT-parameter names.

So we could do either

SELECT funcname INTO varname FROM funcname()

or

SELECT * INTO varname FROM funcname();

or

SELECT funcname() INTO varname

correct?


>
>                        regards, tom lane
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>



-- 
Sergey Konoplev

Blog: http://gray-hemp.blogspot.com /
Linkedin: http://ru.linkedin.com/in/grayhemp /
JID/GTalk: gray...@gmail.com / Skype: gray-hemp / ICQ: 29353802

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql