How to do?

Lists: pgsql-general
From: Robert Partyka <R(dot)Partyka(at)wdg(dot)pl>
To: <pgsql-general(at)postgresql(dot)org>
Subject: How to do?
Date: 2003-07-30 12:17:07
Message-ID: 5.1.0.14.0.20030730141025.009ffb50@mail.alpha.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Hi,

Have question....

How to do such like this:

I have: select <column list> form <tables> where <where statement>;
how to make one column be row numbers in result?

and second one:
have select like above.... and I know that in result is record with e.g.
uid='AC13A1'.
How to reduce result to this record and one record before in result and one
record after in result?

Are this questions just silly problems? :-)

regards


From: Ron Johnson <ron(dot)l(dot)johnson(at)cox(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to do?
Date: 2003-08-01 14:47:38
Message-ID: 1059749258.7508.590.camel@haggis
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Wed, 2003-07-30 at 07:17, Robert Partyka wrote:
> Hi,
>
> Have question....
>
> How to do such like this:
>
> I have: select <column list> form <tables> where <where statement>;
> how to make one column be row numbers in result?
>
> and second one:
> have select like above.... and I know that in result is record with e.g.
> uid='AC13A1'.
> How to reduce result to this record and one record before in result and one
> record after in result?
>
> Are this questions just silly problems? :-)

No, but slightly ambiguous, at least for my old brain.

--
+-----------------------------------------------------------------+
| Ron Johnson, Jr. Home: ron(dot)l(dot)johnson(at)cox(dot)net |
| Jefferson, LA USA |
| |
| "I'm not a vegetarian because I love animals, I'm a vegetarian |
| because I hate vegetables!" |
| unknown |
+-----------------------------------------------------------------+


From: "Shridhar Daithankar" <shridhar_daithankar(at)persistent(dot)co(dot)in>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to do?
Date: 2003-08-01 14:56:02
Message-ID: 3F2ACCDA.31349.157DE385@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On 1 Aug 2003 at 9:47, Ron Johnson wrote:

> On Wed, 2003-07-30 at 07:17, Robert Partyka wrote:
> > Hi,
> >
> > Have question....
> >
> > How to do such like this:
> >
> > I have: select <column list> form <tables> where <where statement>;
> > how to make one column be row numbers in result?

select oid,name from a;

It's oid. Of course you need to have them enabled since they are optional in
recent versions..

> >
> > and second one:
> > have select like above.... and I know that in result is record with e.g.
> > uid='AC13A1'.
> > How to reduce result to this record and one record before in result and one
> > record after in result?

I didn't get that.. could you please elaborate?

Bye
Shridhar

--
Not me, guy. I read the Bash man page each day like a Jehovah's Witness
readsthe Bible. No wait, the Bash man page IS the bible. Excuse me...(More on
confusing aliases, taken from comp.os.linux.misc)


From: Franco Bruno Borghesi <franco(at)akyasociados(dot)com(dot)ar>
To: R(dot)Partyka(at)wdg(dot)pl
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to do?
Date: 2003-08-01 15:34:25
Message-ID: 1059752065.10894.27.camel@taz.oficina
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

I don't know if this is the best solution, but a temp sequence should
work:

CREATE TEMP SEQUENCE tmp_seq;
SELECT
nextval('tmp_seq') AS row_num,
<column list>
FROM
<tables>
WHERE
<where statement>;
DROP SEQUENCE tmp_seq;

And about the rows before and after that you ask, I don't understand...
based on what you mean *before* and *after*? you don't have an order by
clause.

And what do you mean with "I know that in result is record with e.g.
uid='AC13A1'"?
You know this uid *before* sending the query? is it part of your <where
statement>? can you use this value as a hard coded condition for a
subquery?

PS: I don't think your questions are silly.

On Wed, 2003-07-30 at 07:17, Robert Partyka wrote:

> Hi,
>
> Have question....
>
> How to do such like this:
>
> I have: select <column list> form <tables> where <where statement>;
> how to make one column be row numbers in result?
>
> and second one:
> have select like above.... and I know that in result is record with e.g.
> uid='AC13A1'.
> How to reduce result to this record and one record before in result and one
> record after in result?
>
> Are this questions just silly problems? :-)


From: Ron Johnson <ron(dot)l(dot)johnson(at)cox(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to do?
Date: 2003-08-01 15:35:55
Message-ID: 1059752154.7505.593.camel@haggis
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Fri, 2003-08-01 at 09:56, Shridhar Daithankar wrote:
> On 1 Aug 2003 at 9:47, Ron Johnson wrote:
>
> > On Wed, 2003-07-30 at 07:17, Robert Partyka wrote:
> > > Hi,
> > >
> > > Have question....
> > >
> > > How to do such like this:
> > >
> > > I have: select <column list> form <tables> where <where statement>;
> > > how to make one column be row numbers in result?
>
> select oid,name from a;
>
> It's oid. Of course you need to have them enabled since they are optional in
> recent versions..

Oh, *that* row number...

--
+-----------------------------------------------------------------+
| Ron Johnson, Jr. Home: ron(dot)l(dot)johnson(at)cox(dot)net |
| Jefferson, LA USA |
| |
| "I'm not a vegetarian because I love animals, I'm a vegetarian |
| because I hate vegetables!" |
| unknown |
+-----------------------------------------------------------------+