Re: Dynamically accessing columns from a row type in a trigger

2023-08-12 Thread jian he
On Sun, Aug 13, 2023 at 11:27 AM Rhys A.D. Stewart wrote: > > Hey Adrian, > > Thanks for your response. I don't think I explained myself clearly. > pk_col is not the column name. pk_col is a variable that holds the > name of a column. This is one trigger for several tables with varying > structure

Re: Dynamically accessing columns from a row type in a trigger

2023-08-12 Thread David G. Johnston
On Sat, Aug 12, 2023 at 1:10 PM Rhys A.D. Stewart wrote: > Am I missing out on a simpler or more elegant solution? > > No, you are not (at least among SQL and pl/pgsql. SQL is strongly and statically typed. Circumventing that has a cost, but at least you do have tools at hand when you find the

Re: Dynamically accessing columns from a row type in a trigger

2023-08-12 Thread Adrian Klaver
On 8/12/23 20:21, Rhys A.D. Stewart wrote: Hey Adrian, Thanks for your response. I don't think I explained myself clearly. pk_col is not the column name. pk_col is a variable that holds the name of a column. This is one trigger for several tables with varying structures. So pk_col would be a col

Re: Dynamically accessing columns from a row type in a trigger

2023-08-12 Thread Rhys A.D. Stewart
Hey Adrian, Thanks for your response. I don't think I explained myself clearly. pk_col is not the column name. pk_col is a variable that holds the name of a column. This is one trigger for several tables with varying structures. So pk_col would be a column specific to the current TG_TABLE_NAME whe

Re: A Good Beginner's Book

2023-08-12 Thread Anthony DeBarros
Hi, On Sat, Aug 12, 2023 at 6:23 PM Miles Elam wrote: > > On 8/12/23 9:02 a.m., Amn Ojee Uw wrote: > > > > Is there a book to be recommended for PostgreSQL beginners? > I’m the author of Practical SQL from No Starch Press. My book combines an intro to SQL with lessons on data analysis. Learn mo

Re: A Good Beginner's Book

2023-08-12 Thread Miles Elam
> On 8/12/23 9:02 a.m., Amn Ojee Uw wrote: > > Is there a book to be recommended for PostgreSQL beginners? If you are new to relational databases and SQL in general, I recommend the basics of SQL (not Postgres-specific) to start off. The SQL Murder Mystery is a good first experience. https://myst

Re: Dynamically accessing columns from a row type in a trigger

2023-08-12 Thread Adrian Klaver
On 8/12/23 13:09, Rhys A.D. Stewart wrote: Greetings all, I am writing a trigger and would like to know how to dynamically access a column from the "OLD" variable. pk_col is the column name from the table. I've come up with either doing this: EXECUTE format('SELECT $1.%1$I', pk_col) INTO pk_val

Re: Dynamically accessing columns from a row type in a trigger

2023-08-12 Thread Adrian Klaver
On 8/12/23 13:09, Rhys A.D. Stewart wrote: Greetings all, I am writing a trigger and would like to know how to dynamically access a column from the "OLD" variable. pk_col is the column name from the table. I've come up with either doing this: EXECUTE format('SELECT $1.%1$I', pk_col) INTO pk_val

Dynamically accessing columns from a row type in a trigger

2023-08-12 Thread Rhys A.D. Stewart
Greetings all, I am writing a trigger and would like to know how to dynamically access a column from the "OLD" variable. pk_col is the column name from the table. I've come up with either doing this: EXECUTE format('SELECT $1.%1$I', pk_col) INTO pk_val USING OLD; which looks a bit excessive, or

Re: A Good Beginner's Book

2023-08-12 Thread Amn Ojee Uw
*Addendum* : I am using JDBC as the framework. On 8/12/23 9:02 a.m., Amn Ojee Uw wrote: Hello folks. Is there a book to be recommended for PostgreSQL beginners? Thanks in advance.

A Good Beginner's Book

2023-08-12 Thread Amn Ojee Uw
Hello folks. Is there a book to be recommended for PostgreSQL beginners? Thanks in advance.

Re: PgSQL 15.3: Execution plan not using index as expected

2023-08-12 Thread Dürr Software
Thanks Rob, no it's not a problem with the index. It's a problem with the use of CURRENT_USER in the WHERE I submitted a new post on this matter with a test case. Kind regards == Dürr Software Entw. Guggenberg 26, DE-82380 Peißenberg fon: +49-8803-4899016

Re: PgSQL 15.3: Execution plan not using index as expected

2023-08-12 Thread Dürr Software
Thanks Adrian, sorry for the misunderstanding. I ran ANALYZE, it didn't change a thing (as expected). Anyway, I pinned the problem down now: It's the use of CURRENT_USER (or SESSION_USER etc.) in the WHERE condition. If i replace it with 'postgres' (the result of CURRENT_USER) the planner works

Re: How to set default privilege for new users to have no access to other databases?

2023-08-12 Thread Peter J. Holzer
On 2023-08-09 14:35:40 -0400, Erik Nelson wrote: > I have a lab with a database that I would like to use as a "multi-tenant" > database, in that I would like to create a database for each of the > applications that I'm running and segregate access so that user foo and user > bar cannot see anything