Re: Guidance needed on an alternative take on common prefix SQL

2019-08-07 Thread Rob Sargent
On 8/7/19 3:36 AM, Laura Smith wrote: On Wednesday, August 7, 2019 2:01 AM, Andy Colson wrote: On 8/6/19 6:25 PM, Laura Smith wrote: Hi, I've seen various Postgres examples here and elsewhere that deal with the old common-prefix problem (i.e. "given 1234 show me the longest match"). I'm

Re: Why must AUTOCOMMIT be ON to do txn control in plpgsql procedure?

2019-08-07 Thread Bryn Llewellyn
Thanks David. I’m relieved to hear that I’m not the only one who finds it hard to predict the behavior of some things in PostgreSQL just from reading the docs. Hypothesising and experimenting seem to be needed for the trickier cases. You use the phrase "nested transaction”. This Google search

Re: How to check if a field exists in NEW in trigger

2019-08-07 Thread David G. Johnston
On Sun, Aug 4, 2019 at 3:52 PM Igal @ Lucee.org wrote: > I have the following statement in a trigger: > > new.email = lower(new.email); > > When I try to update a record without setting the email column however, I > get an error: > > SQL Error [42703]: ERROR: record "new" has no field

Re: Why must AUTOCOMMIT be ON to do txn control in plpgsql procedure?

2019-08-07 Thread Bryn Llewellyn
Thanks, Adrian. On 07-Aug-2019, at 13:19, Adrian Klaver wrote: On 8/7/19 12:54 PM, Bryn Llewellyn wrote: > Yes, I do believe that I understand this. But there’s no getting away from > the fact that the AUTOCOMMIT mode, and what this implies, is a server-side > phenomenon—at least as several

Re: How to check if a field exists in NEW in trigger

2019-08-07 Thread Igal @ Lucee.org
On 8/5/2019 11:34 AM, Michael Lewis wrote: As a note to the original poster, you might want to check out- https://www.postgresql.org/docs/current/citext.html Thanks, Michael.  I'm familiar with the citext module. There is no reason, however, for an email address to be not-lower-cased, so

Re: Input validation

2019-08-07 Thread Benedict Holland
I think a check will also work but I second triggers. Thanks, ~Ben On Wed, Aug 7, 2019, 2:21 PM Rob Sargent wrote: > > On 8/7/19 12:07 PM, stan wrote: > > Have table that contains employee keys, paired up with work type keys > > (both foreign keys) and a 3rd column that you enter a billing

Re: Why must AUTOCOMMIT be ON to do txn control in plpgsql procedure?

2019-08-07 Thread Benedict Holland
All stored procedures run in their own transaction. My guess is that when you turn off autocommit, you are not committing something after your transaction ends. Also, I have never seen a rollback at the start of a proc. A pure hypothetical is that it is doing nothing or definitely not what you

Re: Why must AUTOCOMMIT be ON to do txn control in plpgsql procedure?

2019-08-07 Thread David G. Johnston
On Wed, Aug 7, 2019 at 12:18 PM Luca Ferrari wrote: > On Wed, Aug 7, 2019 at 8:28 PM Bryn Llewellyn wrote: > > > B.t.w., I noticed that “set transaction isolation level serializable” > must be the very first statement after “rollback” (or “commit”). Even an > invocation of txid_current() after

Re: Recomended front ends?

2019-08-07 Thread Rich Shepard
On Wed, 7 Aug 2019, Igor Korot wrote: On top of what already been said - make sure that the product you are about to start working on will have its requirements clear and concise. This is a critical process that needs to be developed in depth. One criterion that will guide your choice of UI

Re: Recomended front ends?

2019-08-07 Thread Igor Korot
Hi, On Wed, Aug 7, 2019 at 1:57 PM stan wrote: > > I am in the process of defining an application for a very small company > that uses Postgresql for the backend DB. This DB will eventually run on a > hosted machine. As you imagine all of the employees have Windows machines > for their normal

Re: Why must AUTOCOMMIT be ON to do txn control in plpgsql procedure?

2019-08-07 Thread Adrian Klaver
On 8/7/19 12:54 PM, Bryn Llewellyn wrote: Yes, I do believe that I understand this. But there’s no getting away from the fact that the AUTOCOMMIT mode, and what this implies, is a server-side phenomenon—at least as several PostgreSQL experts have assured me. For example, when you use

Re: Why must AUTOCOMMIT be ON to do txn control in plpgsql procedure?

2019-08-07 Thread Bryn Llewellyn
Yes, I do believe that I understand this. But there’s no getting away from the fact that the AUTOCOMMIT mode, and what this implies, is a server-side phenomenon—at least as several PostgreSQL experts have assured me. For example, when you use client-side Python with the psycopg2 driver, then

Re: Recomended front ends?

2019-08-07 Thread Rob Sargent
On 8/7/19 1:38 PM, Adrian Klaver wrote: On 8/7/19 11:57 AM, stan wrote: I am in the process of defining an application for a very small company that uses Postgresql for the backend DB. This DB will eventually run on a hosted machine. As you imagine all of the employees have Windows machines

Re: Recomended front ends?

2019-08-07 Thread Adrian Klaver
On 8/7/19 11:57 AM, stan wrote: I am in the process of defining an application for a very small company that uses Postgresql for the backend DB. This DB will eventually run on a hosted machine. As you imagine all of the employees have Windows machines for their normal work asks. Frankly I am not

Re: Why must AUTOCOMMIT be ON to do txn control in plpgsql procedure?

2019-08-07 Thread Luca Ferrari
On Wed, Aug 7, 2019 at 8:28 PM Bryn Llewellyn wrote: > About your “I believe there is no reason ever to begin a procedure with a > rollback”, I already explained why I did that. My higher goal is to take > advantage of the “serializable” isolation level to safely enforce a multi-row > data

Re: Recomended front ends?

2019-08-07 Thread Igor Korot
Hi, On Wed, Aug 7, 2019 at 1:57 PM stan wrote: > > I am in the process of defining an application for a very small company > that uses Postgresql for the backend DB. This DB will eventually run on a > hosted machine. As you imagine all of the employees have Windows machines > for their normal

Recomended front ends?

2019-08-07 Thread stan
I am in the process of defining an application for a very small company that uses Postgresql for the backend DB. This DB will eventually run on a hosted machine. As you imagine all of the employees have Windows machines for their normal work asks. Frankly I am not very strong on Windows. so I am

Re: Why must AUTOCOMMIT be ON to do txn control in plpgsql procedure?

2019-08-07 Thread Adrian Klaver
On 8/7/19 11:46 AM, Bryn Llewellyn wrote: Thanks for your response, Kyotaro. I’m happy, now, to accept the rule that “call proc_that_does_txn_control()” is legal only when AUTOCOMMIT is ON. Esp. when I’m told (on twitter, by 2ndQuadrant’s Peter Eisentraut, that this rule is “an implementation

Re: Why must AUTOCOMMIT be ON to do txn control in plpgsql procedure?

2019-08-07 Thread Bryn Llewellyn
Thanks for your response, Kyotaro. I’m happy, now, to accept the rule that “call proc_that_does_txn_control()” is legal only when AUTOCOMMIT is ON. Esp. when I’m told (on twitter, by 2ndQuadrant’s Peter Eisentraut, that this rule is “an implementation restriction, for the most part.” See HERE

Re: Why must AUTOCOMMIT be ON to do txn control in plpgsql procedure?

2019-08-07 Thread Bryn Llewellyn
I have a version of the code that I attached with my first email in this thread where I’ve added “raise notice” invocations to show the txid as my p1() and p2() execute. Everything that I see is consistent with what I wrote separately in reply to adrian.kla...@aklaver.com

Re: Input validation

2019-08-07 Thread Rob Sargent
On 8/7/19 12:07 PM, stan wrote: Have table that contains employee keys, paired up with work type keys (both foreign keys) and a 3rd column that you enter a billing rate in. Then I have a table where employees enter their work. I need to validate that the employee, work type pair

Re: Input validation

2019-08-07 Thread Adrian Klaver
On 8/7/19 11:07 AM, stan wrote: Have table that contains employee keys, paired up with work type keys (both foreign keys) and a 3rd column that you enter a billing rate in. Then I have a table where employees enter their work. I need to validate that the employee, work type pair exists,

Input validation

2019-08-07 Thread stan
Have table that contains employee keys, paired up with work type keys (both foreign keys) and a 3rd column that you enter a billing rate in. Then I have a table where employees enter their work. I need to validate that the employee, work type pair exists, before allowing the new record to be

Re: pg_wal fills up on big update query

2019-08-07 Thread Luca Ferrari
On Wed, Aug 7, 2019 at 3:34 PM Daniel Fink (PDF) wrote: > My current idea is to lock both tables completely from access (the queried > and the updated one) so that postgresql does not have to ensure isolation for > concurrent queries by keeping a copy of each row. I'm not sure that locking

Re: pg_wal fills up on big update query

2019-08-07 Thread Rob Sargent
> On Aug 7, 2019, at 7:34 AM, Daniel Fink (PDF) wrote: > > Hi all, > > I have a migration where I > · Add a new nullable column to a table > · update almost every row in this big table (8 million rows) from > another table where I set this new column > > I have also a

Re: Why must AUTOCOMMIT be ON to do txn control in plpgsql procedure?

2019-08-07 Thread Adrian Klaver
On 8/7/19 12:15 AM, Luca Ferrari wrote: On Wed, Aug 7, 2019 at 12:19 AM Bryn Llewellyn wrote: 1. my call p2() starts a txn. Luca P.S: I don't believe that asking on a public mailing list for a company to answer is the right thing to do, you can always ask themselves on your own. Sort of

pg_wal fills up on big update query

2019-08-07 Thread Daniel Fink (PDF)
Hi all, I have a migration where I · Add a new nullable column to a table · update almost every row in this big table (8 million rows) from another table where I set this new column I have also a replication setup running. The database has a size of around 20GB. While the

Re: Why must AUTOCOMMIT be ON to do txn control in plpgsql procedure?

2019-08-07 Thread Kyotaro Horiguchi
Hello, Bryn. At Tue, 6 Aug 2019 15:18:51 -0700, Bryn Llewellyn wrote in > Here’s how I’ve tried to describe what I see for p2() with AUTOCOMMIT ON for > myself: > > 1. my call p2() starts a txn. > > 2. However, during the execution of the proc, the usual autocommit behavior > is

Re: Why must AUTOCOMMIT be ON to do txn control in plpgsql procedure?

2019-08-07 Thread Luca Ferrari
On Wed, Aug 7, 2019 at 12:19 AM Bryn Llewellyn wrote: > 1. my call p2() starts a txn. In my opinion this is the point: a procedure must be "owner" of the transaction to issue transaction control statements. You can watch different behaviors placing here and there txid_current() before and within

Re: Sorting composite types

2019-08-07 Thread Laurenz Albe
Miles Elam wrote: > Is there any way to define a natural sorting order for composite types? For > example, let's say you have a type like: > > CREATE TYPE contrived AS ( > i1 integer, > i2 integer > ); > > The semantics of this contrived type are that the natural order is ascending >