postgrest icon indicating copy to clipboard operation
postgrest copied to clipboard

exclude columns in select *

Open mortezaomidi opened this issue 4 years ago • 6 comments

My problem seems very simple.

I want something like: 'http://localhost:3000/my-table?select=all_except_col_name' How to make such a request?

mortezaomidi avatar Jun 21 '21 16:06 mortezaomidi

That's not possible right now. There's no support in PostgreSQL for a SELECT.. EXCEPT(see this and this).

In theory we could implement such a feature at the PostgREST level, by taking advantage of our schema cache and adding an except query parameter.

GET /mytable?select=*&except=col_name
``

steve-chavez avatar Jun 21 '21 18:06 steve-chavez

I think we already had a question/issue like this - but I can't find it right now.

wolfgangwalther avatar Jun 22 '21 08:06 wolfgangwalther

There's some discussion on -hackers about a feature with some similarity to this: https://www.postgresql.org/message-id/flat/be81d947-f4fe-c062-f107-0f05f8f87ca8%40migops.com

Not exactly the same, but SELECT ... EXCEPT was also mentioned as part of the discussion.

wolfgangwalther avatar Oct 19 '21 07:10 wolfgangwalther

That's not possible right now. There's no support in PostgreSQL for a SELECT.. EXCEPT(see this and this).

In theory we could implement such a feature at the PostgREST level, by taking advantage of our schema cache and adding an except query parameter.

GET /mytable?select=*&except=col_name ``

I was thinking of a simpler syntax like:

GET /mytable?select=-col_name

ogerardin avatar May 09 '25 18:05 ogerardin

Some observations:

  • The use case in https://github.com/PostgREST/postgrest/discussions/4071, describes selecting all but a tsvector column that was used for filtering.
  • On the mailing list thread shared above:
    • There's a similar case for a PostGIS geometry column (ref).
    • Another one for tsvector (ref)
    • The HIDDEN column feature looks really bad for logical data independence IMO. It will break apps.
    • The EXCEPT syntax is the clear winner, the only real opposing argument is that it's not part of the SQL standard.

steve-chavez avatar May 10 '25 01:05 steve-chavez

  • The EXCEPT syntax is the clear winner, the only real opposing argument is that it's not part of the SQL standard.

Although PostgREST is obviouly tied to PostgresQL, I don't think it should be limited by PostgresQL or SQL standard. One of the strong points of PostgREST is precisely that it can be used without having to write a single line of SQL. The implementation might be a bit more complicated now, but it can be simplified later when/if this becomes part of native PostgresQL.

ogerardin avatar May 10 '25 09:05 ogerardin