Overview
PostgREST serves a RESTful API from any existing PostgreSQL database.
v11.2.0 brings you the possibility of using PostgreSQL domains
and casts
to change how your data is presented to web users. We call this feature "domain representations" and it holds some advantages over views.
-- having a uuid domain and a table
create domain app_uuid as uuid;
create table profiles(
id app_uuid
, name text
);
-- we define a function to convert the uuid domain to base64
create or replace function json(app_uuid) returns json as $$
select to_json(encode(uuid_send($1),'base64'));
$$ language sql immutable;
-- and use the function for an implicit cast from domain to json
create cast (app_uuid as json) with function json(app_uuid) as implicit;
-- the format changes when requesting JSON at the API level
curl "http://localhost:3000/profiles" \
-H "Accept: application/json"
[{"id":"hGxP/ZLOTeeNEY4pkp9OxA==","name":"John Doe"}]
-- while the data is kept as is at the database level
select * from profiles;
id | name
--------------------------------------+----------
846c4ffd-92ce-4de7-8d11-8e29929f4ec4 | John Doe
Domain representations also allow you to change the format of the request payload and the format of the filters values. Check the Domain Representations docs for more details.
What is new
API
Admin
- Query the PostgREST version in SQL by @laurenceisla in #2647
- The CLI now has the
--version
option which prints the version information by @laurenceisla in #2856
Resource Embedding
- The documentation now explicitly mentions Foreign Key Joins and includes more complex relationships.
Resource Representation
- nulls=stripped can remove JSON keys which have null values by @taimoorzaeem in #1601
- Improve
details
field of the singular error response by @taimoorzaeem in #1655
Tables and Views
Prefer: return=*
now reply with Preference-Applied headers by @taimoorzaeem in #740
What is fixed
Auth
- Fix applying superuser settings for impersonated role by @steve-chavez in #2896
API
- Fix OPTIONS not accepting all available media types by @steve-chavez in #2821
- Fix
Prefer: missing=default
with DOMAIN default values by @steve-chavez in #2840 - Fix HEAD unnecessarily executing aggregates by @steve-chavez in #2849
- Fix unused index on jsonb/jsonb arrow filter and order (
/bets?data->>contractId=eq.1
and/bets?order=data->>contractId
) by @steve-chavez in #2594 - Fix character and bit columns with fixed length not inserting/updating properly by @laurenceisla in #2861
- Fixes the error "value too long for type character(1)" when the char length of the column was bigger than one.
- Fix null filtering on embedded resource when using a column name equal to the relation name by @steve-chavez in #2862
- Fix function parameters of type character and bit not ignoring length by @laurenceisla in #1586
- Fixes the error "value too long for type character(1)" when the char length of the parameter was bigger than one.
- Fix error when a function returns
RECORD
orSET OF RECORD
by @laurenceisla in #2881
Misc
- Fix compilation on Ubuntu by being compatible with GHC 9.0.2 by @steve-chavez in #2834
Deprecated
Resource Embedding
- Deprecate resource embedding target disambiguation by @steve-chavez in #2863
- The
/table?select=*,other!fk(*)
must be used to disambiguate - The server aids in choosing the
!fk
by sending ahint
on the error whenever an ambiguous request happens.
- The
New Contributors
- @taimoorzaeem made their first contribution in #2873
Full Changelog: v11.1.0...v11.2.0