pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedLocking rows
19+ messages / 13 participants
[nested] [flat]
* Locking rows
@ 2003-02-28 10:26 Jean-Christian Imbeault <jc@mega-bucks.co.jp>
2003-02-28 15:08 ` Re: Locking rows Neil Conway <neilc@samurai.com>
2003-02-28 15:27 ` Re: Locking rows Richard Huxton <dev@archonet.com>
2003-02-28 15:48 ` Re: Locking rows Doug McNaught <doug@mcnaught.org>
2003-02-28 17:16 ` Re: Locking rows Manfred Koizar <mkoi-pg@aon.at>
2003-02-28 20:30 ` Re: Locking rows scott.marlowe <scott.marlowe@ihs.com>
0 siblings, 5 replies; 19+ messages in thread
From: Jean-Christian Imbeault @ 2003-02-28 10:26 UTC (permalink / raw)
To: pgsql-general
I have written an application that prints out data from a database. One
problem I am encountering is in the time it takes to generate the print
file the data may have changed.
I was thinking that a way around this would be to lock the rows that are
used to generate the print file. However I am not quite sure how to best
go about this.
Is locking the rows the best (or simplest) solution?
If locking is a good idea how could I lock and then unlock the rows
returned by this (somewhat ugly) query?
select prod_id, sum(quantity), case when (select stock_qty+cancelled_qty
from stock where pid=prod_id) is null then 0 else (select
stock_qty+cancelled_qty from stock where pid=prod_id) end as stock_qty
from invoice_li, invoices where invoices.id=invoice_id AND dist_id=1 AND
NOT invoices.cancelled AND NOT invoice_li.cancelled group by prod_id;
I will also be doing some other select queries between this one and the
printing (I need to get more information on each prod_id returned).
I've read the iDocs and Bruce's online manual but can seem to find any
info on the syntax for locking other that for SELECT FOR UPDATE. And
even then the docs don't state how to remove the lock created by a
SELECT FOR UPDATE.
Thanks!
Jc
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: Locking rows
2003-02-28 10:26 Locking rows Jean-Christian Imbeault <jc@mega-bucks.co.jp>
@ 2003-02-28 15:08 ` Neil Conway <neilc@samurai.com>
4 siblings, 0 replies; 19+ messages in thread
From: Neil Conway @ 2003-02-28 15:08 UTC (permalink / raw)
To: Jean-Christian Imbeault <jc@mega-bucks.co.jp>; +Cc: pgsql-general
On Fri, 2003-02-28 at 05:26, Jean-Christian Imbeault wrote:
> I have written an application that prints out data from a database. One
> problem I am encountering is in the time it takes to generate the print
> file the data may have changed.
Is that a problem? ISTM that if you need to keep the DB consistent
during the entire print job, you're going to get pretty poor concurrent
performance regardless.
> I've read the iDocs and Bruce's online manual but can seem to find any
> info on the syntax for locking other that for SELECT FOR UPDATE. And
> even then the docs don't state how to remove the lock created by a
> SELECT FOR UPDATE.
The docs on FOR UPDATE say:
This prevents them from being modified or deleted by other transactions
until the current transaction ends; that is, other transactions that
attempt UPDATE, DELETE, or SELECT FOR UPDATE of these rows will be
blocked until the current transaction ends.
Cheers,
Neil
--
Neil Conway <neilc@samurai.com> || PGP Key ID: DB3C29FC
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: Locking rows
2003-02-28 10:26 Locking rows Jean-Christian Imbeault <jc@mega-bucks.co.jp>
@ 2003-02-28 15:27 ` Richard Huxton <dev@archonet.com>
4 siblings, 0 replies; 19+ messages in thread
From: Richard Huxton @ 2003-02-28 15:27 UTC (permalink / raw)
To: Jean-Christian Imbeault <jc@mega-bucks.co.jp>; pgsql-general
On Friday 28 Feb 2003 10:26 am, Jean-Christian Imbeault wrote:
> I have written an application that prints out data from a database. One
> problem I am encountering is in the time it takes to generate the print
> file the data may have changed.
>
> I was thinking that a way around this would be to lock the rows that are
> used to generate the print file. However I am not quite sure how to best
> go about this.
>
> Is locking the rows the best (or simplest) solution?
See the chapter "Concurrency Control" in the User Guide. Sounds like you want
to set transaction level to serializable - no explicit locking required.
This means that within your report-building transaction you don't see any
changes to the database (unless you do any within the transaction itself).
HTH
--
Richard Huxton
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: Locking rows
2003-02-28 10:26 Locking rows Jean-Christian Imbeault <jc@mega-bucks.co.jp>
@ 2003-02-28 15:48 ` Doug McNaught <doug@mcnaught.org>
2003-02-28 16:49 ` Re: Locking rows Jean-Christian Imbeault <jc@mega-bucks.co.jp>
4 siblings, 1 reply; 19+ messages in thread
From: Doug McNaught @ 2003-02-28 15:48 UTC (permalink / raw)
To: Jean-Christian Imbeault <jc@mega-bucks.co.jp>; +Cc: pgsql-general
Jean-Christian Imbeault <jc@mega-bucks.co.jp> writes:
> I have written an application that prints out data from a
> database. One problem I am encountering is in the time it takes to
> generate the print file the data may have changed.
If you use a single query to generate the rows, this will not be a
problem.
If you use multiple queries, execute them all inside a transaction and
you will get a consistent view of the database.
No locking needed.
-Doug
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: Locking rows
2003-02-28 10:26 Locking rows Jean-Christian Imbeault <jc@mega-bucks.co.jp>
2003-02-28 15:48 ` Re: Locking rows Doug McNaught <doug@mcnaught.org>
@ 2003-02-28 16:49 ` Jean-Christian Imbeault <jc@mega-bucks.co.jp>
2003-02-28 18:55 ` Re: Locking rows Jonathan Bartlett <johnnyb@eskimo.com>
2003-02-28 20:10 ` Re: Locking rows Tom Lane <tgl@sss.pgh.pa.us>
2003-02-28 20:48 ` Re: Locking rows Nigel J. Andrews <nandrews@investsystems.co.uk>
2003-02-28 22:25 ` Re: Locking rows Dmitry Tkach <dmitry@openratings.com>
0 siblings, 4 replies; 19+ messages in thread
From: Jean-Christian Imbeault @ 2003-02-28 16:49 UTC (permalink / raw)
To: Doug McNaught <doug@mcnaught.org>; pgsql-general
Doug McNaught wrote:
>
> If you use a single query to generate the rows, this will not be a
> problem.
>
> If you use multiple queries, execute them all inside a transaction and
> you will get a consistent view of the database.
>
> No locking needed.
True but what I am worried about is the data changing while I am in a
transaction.
Right now I want to print customer receipts for items that have been
ordered. But while I gathering the data, which takes more than one
query, a customer might come along and cancel an invoice.
In that case I would print a receipt for something that was cancelled.
I need to find a way to avoid this. I thought locking was a way around
this ... or maybe I need to change my "business" logic or the way the
app gathers the data?
Jc
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: Locking rows
2003-02-28 10:26 Locking rows Jean-Christian Imbeault <jc@mega-bucks.co.jp>
2003-02-28 15:48 ` Re: Locking rows Doug McNaught <doug@mcnaught.org>
2003-02-28 16:49 ` Re: Locking rows Jean-Christian Imbeault <jc@mega-bucks.co.jp>
@ 2003-02-28 18:55 ` Jonathan Bartlett <johnnyb@eskimo.com>
2003-03-01 03:48 ` Re: Locking rows Jean-Christian Imbeault <jc@mega-bucks.co.jp>
3 siblings, 1 reply; 19+ messages in thread
From: Jonathan Bartlett @ 2003-02-28 18:55 UTC (permalink / raw)
To: Jean-Christian Imbeault <jc@mega-bucks.co.jp>; +Cc: Doug McNaught <doug@mcnaught.org>; pgsql-general
> ordered. But while I gathering the data, which takes more than one
> query, a customer might come along and cancel an invoice.
So what? Wouldn't you have the same situation if they cancelled
imediately after you finished the report?
Jon
>
> In that case I would print a receipt for something that was cancelled.
>
> I need to find a way to avoid this. I thought locking was a way around
> this ... or maybe I need to change my "business" logic or the way the
> app gathers the data?
>
> Jc
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: Locking rows
2003-02-28 10:26 Locking rows Jean-Christian Imbeault <jc@mega-bucks.co.jp>
2003-02-28 15:48 ` Re: Locking rows Doug McNaught <doug@mcnaught.org>
2003-02-28 16:49 ` Re: Locking rows Jean-Christian Imbeault <jc@mega-bucks.co.jp>
2003-02-28 18:55 ` Re: Locking rows Jonathan Bartlett <johnnyb@eskimo.com>
@ 2003-03-01 03:48 ` Jean-Christian Imbeault <jc@mega-bucks.co.jp>
2003-03-01 13:39 ` Re: Locking rows Jonathan Bartlett <johnnyb@eskimo.com>
0 siblings, 1 reply; 19+ messages in thread
From: Jean-Christian Imbeault @ 2003-03-01 03:48 UTC (permalink / raw)
To: Jonathan Bartlett <johnnyb@eskimo.com>; +Cc: pgsql-general
Jonathan Bartlett wrote:
>
> So what? Wouldn't you have the same situation if they cancelled
> imediately after you finished the report?
No. While I gather the data necessary to print a receipt I mark the
invoice as non-cancellable.
In other words, I want to make invoices that have had receipts printed
no longer cancellable.
Jc
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: Locking rows
2003-02-28 10:26 Locking rows Jean-Christian Imbeault <jc@mega-bucks.co.jp>
2003-02-28 15:48 ` Re: Locking rows Doug McNaught <doug@mcnaught.org>
2003-02-28 16:49 ` Re: Locking rows Jean-Christian Imbeault <jc@mega-bucks.co.jp>
2003-02-28 18:55 ` Re: Locking rows Jonathan Bartlett <johnnyb@eskimo.com>
2003-03-01 03:48 ` Re: Locking rows Jean-Christian Imbeault <jc@mega-bucks.co.jp>
@ 2003-03-01 13:39 ` Jonathan Bartlett <johnnyb@eskimo.com>
0 siblings, 0 replies; 19+ messages in thread
From: Jonathan Bartlett @ 2003-03-01 13:39 UTC (permalink / raw)
To: Jean-Christian Imbeault <jc@mega-bucks.co.jp>; +Cc: pgsql-general
>
> No. While I gather the data necessary to print a receipt I mark the
> invoice as non-cancellable.
>
Why don't you have two fields - non-cancellable and printed.
In transaction A, you mark everything you want to print as
non-cancellable.
In transaction B, you query for everything that is not printed AND
non-cancellable, and print it, and then update those same records as being
printed.
In addition, you probably want to turn on the maximum isolation level to
fully prevent rewriting records.
Jon
> In other words, I want to make invoices that have had receipts printed
> no longer cancellable.
>
> Jc
>
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: Locking rows
2003-02-28 10:26 Locking rows Jean-Christian Imbeault <jc@mega-bucks.co.jp>
2003-02-28 15:48 ` Re: Locking rows Doug McNaught <doug@mcnaught.org>
2003-02-28 16:49 ` Re: Locking rows Jean-Christian Imbeault <jc@mega-bucks.co.jp>
@ 2003-02-28 20:10 ` Tom Lane <tgl@sss.pgh.pa.us>
3 siblings, 0 replies; 19+ messages in thread
From: Tom Lane @ 2003-02-28 20:10 UTC (permalink / raw)
To: Jean-Christian Imbeault <jc@mega-bucks.co.jp>; +Cc: Doug McNaught <doug@mcnaught.org>; pgsql-general
Jean-Christian Imbeault <jc@mega-bucks.co.jp> writes:
> True but what I am worried about is the data changing while I am in a
> transaction.
Start a serializable-mode transaction, and the data will not change ---
not from your perspective, anyway. Trying to lock it down to not change
from other people's perspectives seems pointless.
regards, tom lane
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: Locking rows
2003-02-28 10:26 Locking rows Jean-Christian Imbeault <jc@mega-bucks.co.jp>
2003-02-28 15:48 ` Re: Locking rows Doug McNaught <doug@mcnaught.org>
2003-02-28 16:49 ` Re: Locking rows Jean-Christian Imbeault <jc@mega-bucks.co.jp>
@ 2003-02-28 20:48 ` Nigel J. Andrews <nandrews@investsystems.co.uk>
2003-03-01 03:50 ` Re: Locking rows Jean-Christian Imbeault <jc@mega-bucks.co.jp>
3 siblings, 1 reply; 19+ messages in thread
From: Nigel J. Andrews @ 2003-02-28 20:48 UTC (permalink / raw)
To: Jean-Christian Imbeault <jc@mega-bucks.co.jp>; +Cc: Doug McNaught <doug@mcnaught.org>; pgsql-general
On Sat, 1 Mar 2003, Jean-Christian Imbeault wrote:
> Doug McNaught wrote:
> >
> > If you use a single query to generate the rows, this will not be a
> > problem.
> >
> > If you use multiple queries, execute them all inside a transaction and
> > you will get a consistent view of the database.
> >
> > No locking needed.
>
> True but what I am worried about is the data changing while I am in a
> transaction.
>
> Right now I want to print customer receipts for items that have been
> ordered. But while I gathering the data, which takes more than one
> query, a customer might come along and cancel an invoice.
>
> In that case I would print a receipt for something that was cancelled.
But then what happens if someone does want to cancel? You're going to say they
can't? Unless the invoice print run is going to take quite a while I think
you're approaching it incorrectly. Even if the print run is going to take along
time you're still approaching it wrong. Say it runs for 2 hours and a customer
wants to cancel but you've locked the tables because of the printing. That
customer has to wait for 2 hours and then still needs the credit note
printing. Why not just let the transaction take a snapshot of a consistent
database, do the print run and do the credit note run as normal. You can't
avoid the credit note run whatever.
> I need to find a way to avoid this. I thought locking was a way around
> this ... or maybe I need to change my "business" logic or the way the
> app gathers the data?
It's not something I've looked at but presumably lock table will lock it so
inserts are also locked out. Obviously select for update can't prevent those
from happening so if cancellations are recorded via insert then there would
appear to be no option but to lock tables.
I could have the wrong end of the stick for what you are wanting. I only vaguly
remember the start of this thread.
Nigel Andrews
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: Locking rows
2003-02-28 10:26 Locking rows Jean-Christian Imbeault <jc@mega-bucks.co.jp>
2003-02-28 15:48 ` Re: Locking rows Doug McNaught <doug@mcnaught.org>
2003-02-28 16:49 ` Re: Locking rows Jean-Christian Imbeault <jc@mega-bucks.co.jp>
2003-02-28 20:48 ` Re: Locking rows Nigel J. Andrews <nandrews@investsystems.co.uk>
@ 2003-03-01 03:50 ` Jean-Christian Imbeault <jc@mega-bucks.co.jp>
0 siblings, 0 replies; 19+ messages in thread
From: Jean-Christian Imbeault @ 2003-03-01 03:50 UTC (permalink / raw)
To: Nigel J. Andrews <nandrews@investsystems.co.uk>; +Cc: pgsql-general
Nigel J. Andrews wrote:
>
> But then what happens if someone does want to cancel? You're going to
say they
> can't?
Exactly. Once you have been charged (i.e. an invoice has been printed)
for an item you cannot cancel it. At least that's the way the the
company would like it to be :)
Jc
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: Locking rows
2003-02-28 10:26 Locking rows Jean-Christian Imbeault <jc@mega-bucks.co.jp>
2003-02-28 15:48 ` Re: Locking rows Doug McNaught <doug@mcnaught.org>
2003-02-28 16:49 ` Re: Locking rows Jean-Christian Imbeault <jc@mega-bucks.co.jp>
@ 2003-02-28 22:25 ` Dmitry Tkach <dmitry@openratings.com>
3 siblings, 0 replies; 19+ messages in thread
From: Dmitry Tkach @ 2003-02-28 22:25 UTC (permalink / raw)
To: Jean-Christian Imbeault <jc@mega-bucks.co.jp>
Jean-Christian Imbeault wrote:
> Doug McNaught wrote:
>
>>If you use a single query to generate the rows, this will not be a
>>problem.
>>
>>If you use multiple queries, execute them all inside a transaction and
>>you will get a consistent view of the database.
>>
>>No locking needed.
>
>
> True but what I am worried about is the data changing while I am in a
> transaction.
>
> Right now I want to print customer receipts for items that have been
> ordered. But while I gathering the data, which takes more than one
> query, a customer might come along and cancel an invoice.
>
> In that case I would print a receipt for something that was cancelled.
>
> I need to find a way to avoid this. I thought locking was a way around
> this ... or maybe I need to change my "business" logic or the way the
> app gathers the data?
>
But can't the customer cancel that invoice one millisecond *after* your application is done?
As far as I can see, from the customer's standpoint, it will look exactly the same, won't it?
Dima
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: Locking rows
2003-02-28 10:26 Locking rows Jean-Christian Imbeault <jc@mega-bucks.co.jp>
@ 2003-02-28 17:16 ` Manfred Koizar <mkoi-pg@aon.at>
4 siblings, 0 replies; 19+ messages in thread
From: Manfred Koizar @ 2003-02-28 17:16 UTC (permalink / raw)
To: Jean-Christian Imbeault <jc@mega-bucks.co.jp>; +Cc: pgsql-general
On Fri, 28 Feb 2003 19:26:55 +0900, Jean-Christian Imbeault
<jc@mega-bucks.co.jp> wrote:
>I have written an application that prints out data from a database. One
>problem I am encountering is in the time it takes to generate the print
>file the data may have changed.
> [...]
>Is locking the rows the best (or simplest) solution?
The simplest (and IMHO best) solution is:
BEGIN;
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
SELECT <this> ...
SELECT <that> ...
SELECT <whatever> ...
COMMIT;
If your entire report is generated from the result of a single SELECT,
you don't even need that BEGIN/SET TRANSACTION/COMMIT stuff.
Servus
Manfred
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: Locking rows
2003-02-28 10:26 Locking rows Jean-Christian Imbeault <jc@mega-bucks.co.jp>
@ 2003-02-28 20:30 ` scott.marlowe <scott.marlowe@ihs.com>
4 siblings, 0 replies; 19+ messages in thread
From: scott.marlowe @ 2003-02-28 20:30 UTC (permalink / raw)
To: Jean-Christian Imbeault <jc@mega-bucks.co.jp>; +Cc: pgsql-general
On Fri, 28 Feb 2003, Jean-Christian Imbeault wrote:
> I have written an application that prints out data from a database. One
> problem I am encountering is in the time it takes to generate the print
> file the data may have changed.
>
> I was thinking that a way around this would be to lock the rows that are
> used to generate the print file. However I am not quite sure how to best
> go about this.
>
> Is locking the rows the best (or simplest) solution?
>
> If locking is a good idea how could I lock and then unlock the rows
> returned by this (somewhat ugly) query?
>
> select prod_id, sum(quantity), case when (select stock_qty+cancelled_qty
> from stock where pid=prod_id) is null then 0 else (select
> stock_qty+cancelled_qty from stock where pid=prod_id) end as stock_qty
> from invoice_li, invoices where invoices.id=invoice_id AND dist_id=1 AND
> NOT invoices.cancelled AND NOT invoice_li.cancelled group by prod_id;
>
> I will also be doing some other select queries between this one and the
> printing (I need to get more information on each prod_id returned).
>
> I've read the iDocs and Bruce's online manual but can seem to find any
> info on the syntax for locking other that for SELECT FOR UPDATE. And
> even then the docs don't state how to remove the lock created by a
> SELECT FOR UPDATE.
No need. Take a look here:
http://www.postgresql.org/docs/view.php?version=7.3&idoc=0&file=transaction-iso.html
And read up on serializable, which should do exactly what you want. I.e.
Even if people are changing the database underneath you, you'll see the
database wholly as if it never changed since your begin; was issued.
^ permalink raw reply [nested|flat] 19+ messages in thread
* Locking rows
@ 2005-05-26 18:47 gabriele zelasco <rubensoda@inwind.it>
2005-05-26 21:50 ` Re: Locking rows Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 19+ messages in thread
From: gabriele zelasco @ 2005-05-26 18:47 UTC (permalink / raw)
To: pgsql-general
Hi.I'm using postgresql 8.0.3 under win2000 and developing with VS2003 (npgsql net provider).
I would like to start a transaction with a sql function.
When user press "edit" button on my form, i would lock the current row.
After user has modified data on form, pressing "save" button I would save the modified row by sql update function and so commit.
Well.The update function works fine.
My problem is to lock the current row.
My code is something like:
CREATE OR REPLACE FUNCTION "public"."new_function" () RETURNS SETOF "public"."table" AS
$body$
begin;
select * from table where field = 'value' for update;
$body$
LANGUAGE 'sql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;
But I get :
ERROR , BEGIN IS NOT ALLOWED IN SQL FUNCTION
What's wrong?
Please tell me if it's a syntax problem
maybe have I to use pgsql ?
How can I lock row in pgsql ?
Thanks in advance.
Internal Virus Database is out-of-date.
Checked by AVG Anti-Virus.
Version: 7.0.289 / Virus Database: 266.11.11 - Release Date: 16/05/2005
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: Locking rows
2005-05-26 18:47 Locking rows gabriele zelasco <rubensoda@inwind.it>
@ 2005-05-26 21:50 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 19+ messages in thread
From: Tom Lane @ 2005-05-26 21:50 UTC (permalink / raw)
To: gabriele zelasco <rubensoda@inwind.it>; +Cc: pgsql-general
"gabriele zelasco" <rubensoda@inwind.it> writes:
> I would like to start a transaction with a sql function.
> When user press "edit" button on my form, i would lock the current row.
> After user has modified data on form, pressing "save" button I would save t=
> he modified row by sql update function and so commit.
This is widely considered a very bad way to design an application.
Consider what happens when the user leaves for lunch, or otherwise
lets the app sit for a long time. See the list archives for prior
discussions of the issue.
But in any case, the answer to your question is to use "SELECT FOR
UPDATE" to retrieve the row. And you can't start a transaction
inside a function, because by definition you'll already be in one.
regards, tom lane
^ permalink raw reply [nested|flat] 19+ messages in thread
* "Locking rows"
@ 2019-08-12 17:51 stan <stanb@panix.com>
2019-08-12 19:14 ` Re: "Locking rows" Adrian Klaver <adrian.klaver@aklaver.com>
0 siblings, 1 reply; 19+ messages in thread
From: stan @ 2019-08-12 17:51 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
I have a customer requirement/desire. The system is (among other things)
essentially a employee time sheet. The manager wants for an employee to not
be able to modify a given row in the table they enter time into once it is
committed. I personally see issues with this, but I am willing to try to give
him what he wants. If it creates issues we can sort them out, once he sees
the issues.
The only way I see to do this is to add a column (call it lock). I will
then set this up as a default entry with a value of TRUE. The form the
employee uses to enter this will, of course, not display this column. The
I will create a function that on UPDATE, checks for the presence of the 1 in
this row, and rejects the update. Then I will give the manager a form where
he can set this flag to FALSE.
Looks ugly, and convulsed to me.
Is here a more "database native" way to handle this?
--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: "Locking rows"
2019-08-12 17:51 "Locking rows" stan <stanb@panix.com>
@ 2019-08-12 19:14 ` Adrian Klaver <adrian.klaver@aklaver.com>
2019-08-12 20:15 ` Re: "Locking rows" Adrian Klaver <adrian.klaver@aklaver.com>
0 siblings, 1 reply; 19+ messages in thread
From: Adrian Klaver @ 2019-08-12 19:14 UTC (permalink / raw)
To: stan <stanb@panix.com>; pgsql-general@lists.postgresql.org
On 8/12/19 10:51 AM, stan wrote:
> I have a customer requirement/desire. The system is (among other things)
> essentially a employee time sheet. The manager wants for an employee to not
> be able to modify a given row in the table they enter time into once it is
> committed. I personally see issues with this, but I am willing to try to give
> him what he wants. If it creates issues we can sort them out, once he sees
> the issues.
>
> The only way I see to do this is to add a column (call it lock). I will
> then set this up as a default entry with a value of TRUE. The form the
> employee uses to enter this will, of course, not display this column. The
> I will create a function that on UPDATE, checks for the presence of the 1 in
> this row, and rejects the update. Then I will give the manager a form where
> he can set this flag to FALSE.
>
> Looks ugly, and convulsed to me.
>
> Is here a more "database native" way to handle this?
Depends on who is doing the database record changes.
In other words are there defined roles:
https://www.postgresql.org/docs/11/sql-createrole.html
for the object(table) and the entity working with the table?
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 19+ messages in thread
* Re: "Locking rows"
2019-08-12 17:51 "Locking rows" stan <stanb@panix.com>
2019-08-12 19:14 ` Re: "Locking rows" Adrian Klaver <adrian.klaver@aklaver.com>
@ 2019-08-12 20:15 ` Adrian Klaver <adrian.klaver@aklaver.com>
0 siblings, 0 replies; 19+ messages in thread
From: Adrian Klaver @ 2019-08-12 20:15 UTC (permalink / raw)
To: stan <stanb@panix.com>; +Cc: pgsql-general@lists.postgresql.org
On 8/12/19 1:07 PM, stan wrote:
> On Mon, Aug 12, 2019 at 12:14:25PM -0700, Adrian Klaver wrote:
>> On 8/12/19 10:51 AM, stan wrote:
>>> I have a customer requirement/desire. The system is (among other things)
>>> essentially a employee time sheet. The manager wants for an employee to not
>>> be able to modify a given row in the table they enter time into once it is
>>> committed. I personally see issues with this, but I am willing to try to give
>>> him what he wants. If it creates issues we can sort them out, once he sees
>>> the issues.
>>>
>>> The only way I see to do this is to add a column (call it lock). I will
>>> then set this up as a default entry with a value of TRUE. The form the
>>> employee uses to enter this will, of course, not display this column. The
>>> I will create a function that on UPDATE, checks for the presence of the 1 in
>>> this row, and rejects the update. Then I will give the manager a form where
>>> he can set this flag to FALSE.
>>>
>>> Looks ugly, and convulsed to me.
>>>
>>> Is here a more "database native" way to handle this?
>>
>> Depends on who is doing the database record changes.
>>
>> In other words are there defined roles:
>>
>> https://www.postgresql.org/docs/11/sql-createrole.html
>>
>> for the object(table) and the entity working with the table?
>>
> OK, maybe I could set up the "user" role, such that it does not have the
> UPDATE permission on this table, just the INSERT one? Of course the "admin"
> role would have the UPDATE attribute for this table.
'user' should also have SELECT if you want them to see their records.
>
> Make sense?
Yes.
>
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 19+ messages in thread
end of thread, other threads:[~2019-08-12 20:15 UTC | newest]
Thread overview: 19+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-02-28 10:26 Locking rows Jean-Christian Imbeault <jc@mega-bucks.co.jp>
2003-02-28 15:08 ` Neil Conway <neilc@samurai.com>
2003-02-28 15:27 ` Richard Huxton <dev@archonet.com>
2003-02-28 15:48 ` Doug McNaught <doug@mcnaught.org>
2003-02-28 16:49 ` Jean-Christian Imbeault <jc@mega-bucks.co.jp>
2003-02-28 18:55 ` Jonathan Bartlett <johnnyb@eskimo.com>
2003-03-01 03:48 ` Jean-Christian Imbeault <jc@mega-bucks.co.jp>
2003-03-01 13:39 ` Jonathan Bartlett <johnnyb@eskimo.com>
2003-02-28 20:10 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-02-28 20:48 ` Nigel J. Andrews <nandrews@investsystems.co.uk>
2003-03-01 03:50 ` Jean-Christian Imbeault <jc@mega-bucks.co.jp>
2003-02-28 22:25 ` Dmitry Tkach <dmitry@openratings.com>
2003-02-28 17:16 ` Manfred Koizar <mkoi-pg@aon.at>
2003-02-28 20:30 ` scott.marlowe <scott.marlowe@ihs.com>
2005-05-26 18:47 Locking rows gabriele zelasco <rubensoda@inwind.it>
2005-05-26 21:50 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-08-12 17:51 "Locking rows" stan <stanb@panix.com>
2019-08-12 19:14 ` Re: "Locking rows" Adrian Klaver <adrian.klaver@aklaver.com>
2019-08-12 20:15 ` Re: "Locking rows" Adrian Klaver <adrian.klaver@aklaver.com>
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