pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Can user specification of a column value be required when querying a view ?
11+ messages / 6 participants
[nested] [flat]

* Can user specification of a column value be required when querying a view ?
@ 2023-11-20 21:41 David Gauthier <dfgpostgres@gmail.com>
  2023-11-20 21:44 ` Re: Can user specification of a column value be required when querying a view ? Steve Baldwin <steve.baldwin@gmail.com>
  2023-11-20 21:44 ` Re: Can user specification of a column value be required when querying a view ? Christophe Pettus <xof@thebuild.com>
  0 siblings, 2 replies; 11+ messages in thread

From: David Gauthier @ 2023-11-20 21:41 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Hi:

I have a view that I want  to require user specification for a specific
column before the query starts (if that makes sense).

Example
I want the users to be required to provide a value for ssn in the following
query...
"select * from huge_view *where ssn = '106-91-9930'* "
I never want them to query the view without specifying ssn.
It has to do with resources and practicality.

Is there a way to do that ?
Thanks

^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Can user specification of a column value be required when querying a view ?
  2023-11-20 21:41 Can user specification of a column value be required when querying a view ? David Gauthier <dfgpostgres@gmail.com>
@ 2023-11-20 21:44 ` Steve Baldwin <steve.baldwin@gmail.com>
  1 sibling, 0 replies; 11+ messages in thread

From: Steve Baldwin @ 2023-11-20 21:44 UTC (permalink / raw)
  To: David Gauthier <dfgpostgres@gmail.com>; +Cc: pgsql-general@lists.postgresql.org

Maybe you could create a function that has a required parameter, so rather
than 'select * from huge_view where .." they do 'select * from
function(some_ssn) [where...]' ?

That function would then query the view using the supplied ssn.

Just a thought.

Steve

On Tue, Nov 21, 2023 at 8:41 AM David Gauthier <dfgpostgres@gmail.com>
wrote:

> Hi:
>
> I have a view that I want  to require user specification for a specific
> column before the query starts (if that makes sense).
>
> Example
> I want the users to be required to provide a value for ssn in the
> following query...
> "select * from huge_view *where ssn = '106-91-9930'* "
> I never want them to query the view without specifying ssn.
> It has to do with resources and practicality.
>
> Is there a way to do that ?
> Thanks
>
>

^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Can user specification of a column value be required when querying a view ?
  2023-11-20 21:41 Can user specification of a column value be required when querying a view ? David Gauthier <dfgpostgres@gmail.com>
@ 2023-11-20 21:44 ` Christophe Pettus <xof@thebuild.com>
  2023-11-20 22:12   ` Re: Can user specification of a column value be required when querying a view ? David Gauthier <dfgpostgres@gmail.com>
  2023-11-21 00:24   ` Re: Can user specification of a column value be required when querying a view ? Alan Hodgson <ahodgson@lists.simkin.ca>
  1 sibling, 2 replies; 11+ messages in thread

From: Christophe Pettus @ 2023-11-20 21:44 UTC (permalink / raw)
  To: David Gauthier <dfgpostgres@gmail.com>; +Cc: pgsql-general@lists.postgresql.org



> On Nov 20, 2023, at 13:41, David Gauthier <dfgpostgres@gmail.com> wrote:
> I want the users to be required to provide a value for ssn in the following query... 
> "select * from huge_view where ssn = '106-91-9930' "
> I never want them to query the view without specifying ssn.
> It has to do with resources and practicality.
> 
> Is there a way to do that ?

Not in a way that PostgreSQL itself will enforce.  If you are concerned about a query running wild and taking up resources, setting statement_timeout for the user that will be running these queries is the best way forward.  A user that has general access to PostgreSQL and can run arbitrary queries will be able to craft a query that takes up a lot of system time and memory without too much trouble.




^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Can user specification of a column value be required when querying a view ?
  2023-11-20 21:41 Can user specification of a column value be required when querying a view ? David Gauthier <dfgpostgres@gmail.com>
  2023-11-20 21:44 ` Re: Can user specification of a column value be required when querying a view ? Christophe Pettus <xof@thebuild.com>
@ 2023-11-20 22:12   ` David Gauthier <dfgpostgres@gmail.com>
  1 sibling, 0 replies; 11+ messages in thread

From: David Gauthier @ 2023-11-20 22:12 UTC (permalink / raw)
  To: Christophe Pettus <xof@thebuild.com>; +Cc: pgsql-general@lists.postgresql.org

OK, didn't think so, just checking.  Thanks for verifying !

On Mon, Nov 20, 2023 at 4:45 PM Christophe Pettus <xof@thebuild.com> wrote:

>
>
> > On Nov 20, 2023, at 13:41, David Gauthier <dfgpostgres@gmail.com> wrote:
> > I want the users to be required to provide a value for ssn in the
> following query...
> > "select * from huge_view where ssn = '106-91-9930' "
> > I never want them to query the view without specifying ssn.
> > It has to do with resources and practicality.
> >
> > Is there a way to do that ?
>
> Not in a way that PostgreSQL itself will enforce.  If you are concerned
> about a query running wild and taking up resources, setting
> statement_timeout for the user that will be running these queries is the
> best way forward.  A user that has general access to PostgreSQL and can run
> arbitrary queries will be able to craft a query that takes up a lot of
> system time and memory without too much trouble.

^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Can user specification of a column value be required when querying a view ?
  2023-11-20 21:41 Can user specification of a column value be required when querying a view ? David Gauthier <dfgpostgres@gmail.com>
  2023-11-20 21:44 ` Re: Can user specification of a column value be required when querying a view ? Christophe Pettus <xof@thebuild.com>
@ 2023-11-21 00:24   ` Alan Hodgson <ahodgson@lists.simkin.ca>
  2023-11-21 03:03     ` Re: Can user specification of a column value be required when querying a view ? Ron Johnson <ronljohnsonjr@gmail.com>
  1 sibling, 1 reply; 11+ messages in thread

From: Alan Hodgson @ 2023-11-21 00:24 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On Mon, 2023-11-20 at 13:44 -0800, Christophe Pettus wrote:
> 
> 
> > On Nov 20, 2023, at 13:41, David Gauthier <dfgpostgres@gmail.com>
> > wrote:
> > I want the users to be required to provide a value for ssn in the
> > following query... 
> > "select * from huge_view where ssn = '106-91-9930' "
> > I never want them to query the view without specifying ssn.
> > It has to do with resources and practicality.
> > 
> > Is there a way to do that ?
> 
> Not in a way that PostgreSQL itself will enforce.  If you are
> concerned about a query running wild and taking up resources,
> setting statement_timeout for the user that will be running these
> queries is the best way forward.  A user that has general access to
> PostgreSQL and can run arbitrary queries will be able to craft a
> query that takes up a lot of system time and memory without too
> much trouble.

If it's really about SSN's it might be more about bulk access to PII
than performance.

A function is probably the right choice in either case.

^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Can user specification of a column value be required when querying a view ?
  2023-11-20 21:41 Can user specification of a column value be required when querying a view ? David Gauthier <dfgpostgres@gmail.com>
  2023-11-20 21:44 ` Re: Can user specification of a column value be required when querying a view ? Christophe Pettus <xof@thebuild.com>
  2023-11-21 00:24   ` Re: Can user specification of a column value be required when querying a view ? Alan Hodgson <ahodgson@lists.simkin.ca>
@ 2023-11-21 03:03     ` Ron Johnson <ronljohnsonjr@gmail.com>
  2023-11-24 18:00       ` Re: Can user specification of a column value be required when querying a view ? Peter J. Holzer <hjp-pgsql@hjp.at>
  0 siblings, 1 reply; 11+ messages in thread

From: Ron Johnson @ 2023-11-21 03:03 UTC (permalink / raw)
  To: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

Or row level security.

On Mon, Nov 20, 2023 at 9:25 PM Alan Hodgson <ahodgson@lists.simkin.ca>
wrote:

> On Mon, 2023-11-20 at 13:44 -0800, Christophe Pettus wrote:
>
>
>
> On Nov 20, 2023, at 13:41, David Gauthier <dfgpostgres@gmail.com> wrote:
> I want the users to be required to provide a value for ssn in the
> following query...
> "select * from huge_view where ssn = '106-91-9930' "
> I never want them to query the view without specifying ssn.
> It has to do with resources and practicality.
>
> Is there a way to do that ?
>
>
> Not in a way that PostgreSQL itself will enforce.  If you are concerned
> about a query running wild and taking up resources, setting
> statement_timeout for the user that will be running these queries is the
> best way forward.  A user that has general access to PostgreSQL and can run
> arbitrary queries will be able to craft a query that takes up a lot of
> system time and memory without too much trouble.
>
>
> If it's really about SSN's it might be more about bulk access to PII than
> performance.
>
> A function is probably the right choice in either case.
>

^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Can user specification of a column value be required when querying a view ?
  2023-11-20 21:41 Can user specification of a column value be required when querying a view ? David Gauthier <dfgpostgres@gmail.com>
  2023-11-20 21:44 ` Re: Can user specification of a column value be required when querying a view ? Christophe Pettus <xof@thebuild.com>
  2023-11-21 00:24   ` Re: Can user specification of a column value be required when querying a view ? Alan Hodgson <ahodgson@lists.simkin.ca>
  2023-11-21 03:03     ` Re: Can user specification of a column value be required when querying a view ? Ron Johnson <ronljohnsonjr@gmail.com>
@ 2023-11-24 18:00       ` Peter J. Holzer <hjp-pgsql@hjp.at>
  2023-11-24 18:06         ` Re: Can user specification of a column value be required when querying a view ? Ron Johnson <ronljohnsonjr@gmail.com>
  0 siblings, 1 reply; 11+ messages in thread

From: Peter J. Holzer @ 2023-11-24 18:00 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 2023-11-20 22:03:06 -0500, Ron Johnson wrote:
> Or row level security.

Does that help here? AIUI row level security can be used to limit access
to specific rows (e.g. user alex can access info about ssn '106-91-9930'
but not '234-56-7890') but not how many rows can be accessed in a single
query.

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Can user specification of a column value be required when querying a view ?
  2023-11-20 21:41 Can user specification of a column value be required when querying a view ? David Gauthier <dfgpostgres@gmail.com>
  2023-11-20 21:44 ` Re: Can user specification of a column value be required when querying a view ? Christophe Pettus <xof@thebuild.com>
  2023-11-21 00:24   ` Re: Can user specification of a column value be required when querying a view ? Alan Hodgson <ahodgson@lists.simkin.ca>
  2023-11-21 03:03     ` Re: Can user specification of a column value be required when querying a view ? Ron Johnson <ronljohnsonjr@gmail.com>
  2023-11-24 18:00       ` Re: Can user specification of a column value be required when querying a view ? Peter J. Holzer <hjp-pgsql@hjp.at>
@ 2023-11-24 18:06         ` Ron Johnson <ronljohnsonjr@gmail.com>
  2023-11-25 09:49           ` Re: Can user specification of a column value be required when querying a view ? Peter J. Holzer <hjp-pgsql@hjp.at>
  0 siblings, 1 reply; 11+ messages in thread

From: Ron Johnson @ 2023-11-24 18:06 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On Fri, Nov 24, 2023 at 1:01 PM Peter J. Holzer <hjp-pgsql@hjp.at> wrote:

> On 2023-11-20 22:03:06 -0500, Ron Johnson wrote:
> > Or row level security.
>
> Does that help here? AIUI row level security can be used to limit access
> to specific rows (e.g. user alex can access info about ssn '106-91-9930'
> but not '234-56-7890') but not how many rows can be accessed in a single
> query.
>

I don't think OP indicated that ssn in a unique key.

^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Can user specification of a column value be required when querying a view ?
  2023-11-20 21:41 Can user specification of a column value be required when querying a view ? David Gauthier <dfgpostgres@gmail.com>
  2023-11-20 21:44 ` Re: Can user specification of a column value be required when querying a view ? Christophe Pettus <xof@thebuild.com>
  2023-11-21 00:24   ` Re: Can user specification of a column value be required when querying a view ? Alan Hodgson <ahodgson@lists.simkin.ca>
  2023-11-21 03:03     ` Re: Can user specification of a column value be required when querying a view ? Ron Johnson <ronljohnsonjr@gmail.com>
  2023-11-24 18:00       ` Re: Can user specification of a column value be required when querying a view ? Peter J. Holzer <hjp-pgsql@hjp.at>
  2023-11-24 18:06         ` Re: Can user specification of a column value be required when querying a view ? Ron Johnson <ronljohnsonjr@gmail.com>
@ 2023-11-25 09:49           ` Peter J. Holzer <hjp-pgsql@hjp.at>
  2023-11-25 15:49             ` Re: Can user specification of a column value be required when querying a view ? Ron Johnson <ronljohnsonjr@gmail.com>
  0 siblings, 1 reply; 11+ messages in thread

From: Peter J. Holzer @ 2023-11-25 09:49 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 2023-11-24 13:06:45 -0500, Ron Johnson wrote:
> On Fri, Nov 24, 2023 at 1:01 PM Peter J. Holzer <hjp-pgsql@hjp.at> wrote:
>     On 2023-11-20 22:03:06 -0500, Ron Johnson wrote:
>     > Or row level security.
> 
>     Does that help here? AIUI row level security can be used to limit access
>     to specific rows (e.g. user alex can access info about ssn '106-91-9930'
>     but not '234-56-7890') but not how many rows can be accessed in a single
>     query.
> 
> 
> I don't think OP indicated that ssn in a unique key. 

No he didn't, but that's IMHO not relevant to the possibility of using
row level security. If a row level security allows a user to select a
row, that row can be selected by any query, including «select * from t».
I don't see a way to use RLS to ensure that a query can only return a
sufficiently small subset of the total rows a user has access to.
How would you do that?

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Can user specification of a column value be required when querying a view ?
  2023-11-20 21:41 Can user specification of a column value be required when querying a view ? David Gauthier <dfgpostgres@gmail.com>
  2023-11-20 21:44 ` Re: Can user specification of a column value be required when querying a view ? Christophe Pettus <xof@thebuild.com>
  2023-11-21 00:24   ` Re: Can user specification of a column value be required when querying a view ? Alan Hodgson <ahodgson@lists.simkin.ca>
  2023-11-21 03:03     ` Re: Can user specification of a column value be required when querying a view ? Ron Johnson <ronljohnsonjr@gmail.com>
  2023-11-24 18:00       ` Re: Can user specification of a column value be required when querying a view ? Peter J. Holzer <hjp-pgsql@hjp.at>
  2023-11-24 18:06         ` Re: Can user specification of a column value be required when querying a view ? Ron Johnson <ronljohnsonjr@gmail.com>
  2023-11-25 09:49           ` Re: Can user specification of a column value be required when querying a view ? Peter J. Holzer <hjp-pgsql@hjp.at>
@ 2023-11-25 15:49             ` Ron Johnson <ronljohnsonjr@gmail.com>
  2023-11-26 00:22               ` Re: Can user specification of a column value be required when querying a view ? Peter J. Holzer <hjp-pgsql@hjp.at>
  0 siblings, 1 reply; 11+ messages in thread

From: Ron Johnson @ 2023-11-25 15:49 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On Sat, Nov 25, 2023 at 4:49 AM Peter J. Holzer <hjp-pgsql@hjp.at> wrote:

> On 2023-11-24 13:06:45 -0500, Ron Johnson wrote:
> > On Fri, Nov 24, 2023 at 1:01 PM Peter J. Holzer <hjp-pgsql@hjp.at>
> wrote:
> >     On 2023-11-20 22:03:06 -0500, Ron Johnson wrote:
> >     > Or row level security.
> >
> >     Does that help here? AIUI row level security can be used to limit
> access
> >     to specific rows (e.g. user alex can access info about ssn
> '106-91-9930'
> >     but not '234-56-7890') but not how many rows can be accessed in a
> single
> >     query.
> >
> >
> > I don't think OP indicated that ssn in a unique key.
>
> No he didn't, but that's IMHO not relevant to the possibility of using
> row level security. If a row level security allows a user to select a
> row, that row can be selected by any query, including «select * from t».
> I don't see a way to use RLS to ensure that a query can only return a
> sufficiently small subset of the total rows a user has access to.
> How would you do that?
>

It's an alternative to functions for restricting the client to only his
data.

^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Can user specification of a column value be required when querying a view ?
  2023-11-20 21:41 Can user specification of a column value be required when querying a view ? David Gauthier <dfgpostgres@gmail.com>
  2023-11-20 21:44 ` Re: Can user specification of a column value be required when querying a view ? Christophe Pettus <xof@thebuild.com>
  2023-11-21 00:24   ` Re: Can user specification of a column value be required when querying a view ? Alan Hodgson <ahodgson@lists.simkin.ca>
  2023-11-21 03:03     ` Re: Can user specification of a column value be required when querying a view ? Ron Johnson <ronljohnsonjr@gmail.com>
  2023-11-24 18:00       ` Re: Can user specification of a column value be required when querying a view ? Peter J. Holzer <hjp-pgsql@hjp.at>
  2023-11-24 18:06         ` Re: Can user specification of a column value be required when querying a view ? Ron Johnson <ronljohnsonjr@gmail.com>
  2023-11-25 09:49           ` Re: Can user specification of a column value be required when querying a view ? Peter J. Holzer <hjp-pgsql@hjp.at>
  2023-11-25 15:49             ` Re: Can user specification of a column value be required when querying a view ? Ron Johnson <ronljohnsonjr@gmail.com>
@ 2023-11-26 00:22               ` Peter J. Holzer <hjp-pgsql@hjp.at>
  0 siblings, 0 replies; 11+ messages in thread

From: Peter J. Holzer @ 2023-11-26 00:22 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 2023-11-25 10:49:56 -0500, Ron Johnson wrote:
> On Sat, Nov 25, 2023 at 4:49 AM Peter J. Holzer <hjp-pgsql@hjp.at> wrote:
>     On 2023-11-24 13:06:45 -0500, Ron Johnson wrote:
>     > On Fri, Nov 24, 2023 at 1:01 PM Peter J. Holzer <hjp-pgsql@hjp.at> wrote:
>     >     On 2023-11-20 22:03:06 -0500, Ron Johnson wrote:
>     >     > Or row level security.
>     >
>     >     Does that help here?
[...]
> It's an alternative to functions for restricting the client to only his data.

Which isn't the problem here. So RLS doesn't help.

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 11+ messages in thread


end of thread, other threads:[~2023-11-26 00:22 UTC | newest]

Thread overview: 11+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-11-20 21:41 Can user specification of a column value be required when querying a view ? David Gauthier <dfgpostgres@gmail.com>
2023-11-20 21:44 ` Steve Baldwin <steve.baldwin@gmail.com>
2023-11-20 21:44 ` Christophe Pettus <xof@thebuild.com>
2023-11-20 22:12   ` David Gauthier <dfgpostgres@gmail.com>
2023-11-21 00:24   ` Alan Hodgson <ahodgson@lists.simkin.ca>
2023-11-21 03:03     ` Ron Johnson <ronljohnsonjr@gmail.com>
2023-11-24 18:00       ` Peter J. Holzer <hjp-pgsql@hjp.at>
2023-11-24 18:06         ` Ron Johnson <ronljohnsonjr@gmail.com>
2023-11-25 09:49           ` Peter J. Holzer <hjp-pgsql@hjp.at>
2023-11-25 15:49             ` Ron Johnson <ronljohnsonjr@gmail.com>
2023-11-26 00:22               ` Peter J. Holzer <hjp-pgsql@hjp.at>

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