pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruce Momjian <pgman@candle.pha.pa.us>
To: tp@emaze.net
Cc: pgsql-sql@postgresql.org
Subject: Re: UPDATE & LIMIT together?
Date: Wed, 28 Aug 2002 13:01:36 -0400 (EDT)
Message-ID: <200208281701.g7SH1aI20777@candle.pha.pa.us> (raw)
In-Reply-To: <20020828160929.GL20155@emaze.net>


You have to use a subquery returning the tables primary key to the
UPDATE:

	UPDATE tab SET x=1
	WHERE (primkey, col) IN (
		SELECT primkey,col FROM tab 
		ORDER BY col 
		LIMIT 10)

---------------------------------------------------------------------------

tp wrote:
-- Start of PGP signed section.
> Hi
> 
> I want to SELECT at max. 10 rows and SET a variable for the
> select 10 rows with the same query.
> 
> Under mysql i can use:
> UPDATE table SET uniq_iq=12345 LIMIT 10
> SELECT * FROM table WHERE uniq_id=1234;
> 
> This is not supported by postgres.
> 
> Is there some easy solution that does not require locking?
> 
> 
> -tp
-- End of PGP section, PGP failed!

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073



view thread (4+ messages)  latest in thread

Message-ID: <200208281701.g7SH1aI20777@candle.pha.pa.us>
Permalink:  ../200208281701.g7SH1aI20777@candle.pha.pa.us/
Also on:    postgresql.org/message-id/200208281701.g7SH1aI20777@candle.pha.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: pgman@candle.pha.pa.us, tp@emaze.net
  Subject: Re: UPDATE & LIMIT together?
  In-Reply-To: <200208281701.g7SH1aI20777@candle.pha.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox