Skip site navigation (1) Skip section navigation (2)

Re: including limited lines depending on input parameter

From: Jim Nasby <decibel(at)decibel(dot)org>
To: kvnsmnsn(at)cs(dot)byu(dot)edu
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: including limited lines depending on input parameter
Date: 2007-05-06 15:23:24
Message-ID: BB540894-8381-415F-B3F2-0C4B65575580@decibel.org (view raw or flat)
Thread:
Lists: pgsql-novice
On Apr 27, 2007, at 11:10 AM, kvnsmnsn(at)cs(dot)byu(dot)edu wrote:
>      Okay, this is me back again regarding those two tables I needed
> to join again, <abc> and <def>.  Once these tables are joined together
> the resulting table has two fields of interest, <n> and <p>.  There
> can be multiple <p> values for one <n> value.  I have an input parame-
> ter <i> that can have three values, 1, 2, or 3+.  Based on <i> I need
> to include in the output table either one <p> value for each <n> va-
> lue (as far as I know chosen at random) if one exists, two <p> values
> for each <n> value (again chosen at random) if two exist, or all <p>
> values for each <n> value, respectively.
>
>      Does anyone know how I would go about generating such an output
> table?
>
>      I have a book _Practical PostgreSQL_ that I thought would help me
> figure out how to do this (since my SQL server is PostgreSQL), but so
> far it has been no use.  Any information on this would be greatly ap-
> preciated.

You'll want to use the LIMIT clause, though in the 3+ case you'll  
want to have no LIMIT. You should probably wrap all this in a plpgsql  
function.
--
Jim Nasby                                            jim(at)nasby(dot)net
EnterpriseDB      http://enterprisedb.com      512.569.9461 (cell)



In response to

pgsql-novice by date

Next:From: Jim NasbyDate: 2007-05-06 15:25:39
Subject: Re: Emulating partitioning in postgresql 8.0?
Previous:From: Oliveiros CristinaDate: 2007-05-06 11:56:03
Subject: Re: Importing a CSV file to a table on Postgres

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group