Questions tagged [postgrest]

PostgREST serves a fully RESTful API from any existing PostgreSQL database. It provides a cleaner, more standards-compliant, faster API. It differs from the other emerging API servers by taking an opinionated stance on the full implementation of API by being operationally sound and simple to deploy, by delivering built-in security with JSON Web Tokens plus database roles, and by fully embracing the relational model.

Introduction

PostgREST is a standalone web server that turns your PostgreSQL database directly into a RESTful API. The structural constraints and permissions in the database determine the API endpoints and operations.

Motivation

Using PostgREST is an alternative to manual CRUD programming. Custom API servers suffer problems. Writing business logic often duplicates, ignores or hobbles database structure. Object-relational mapping is a leaky abstraction leading to slow imperative code. The PostgREST philosophy establishes a single declarative source of truth: the data itself.

Declarative Programming

It's easier to ask Postgres to join data for you and let its query planner figure out the details than to loop through rows yourself. It's easier to assign permissions to db objects than to add guards in controllers. (This is especially true for cascading permissions in data dependencies.) It's easier to set constraints than to litter code with sanity checks.

Leakproof Abstraction

There is no ORM involved. Creating new views happens in SQL with known performance implications. A database administrator can now create an API from scratch with no custom programming.

Embracing the Relational Model

In 1970 E. F. Codd criticized the then-dominant hierarchical model of databases in his article A Relational Model of Data for Large Shared Data Banks. Reading the article reveals a striking similarity between hierarchical databases and nested http routes. With PostgREST we attempt to use flexible filtering and embedding rather than nested routes.

One Thing Well

PostgREST has a focused scope. It works well with other tools like Nginx. This forces you to cleanly separate the data-centric CRUD operations from other concerns. Use a collection of sharp tools rather than building a big ball of mud.

136 questions
3
votes
1 answer

PostgREST error on connecting in AWS using secrets

Currently deploying PostgREST in AWS. When I use Fargate and just hardcoded type in the environment variables for the connection string, the machine works like a charm. However I recently replaced these values with secrets. In the secret I…
JustLudo
  • 1,690
  • 12
  • 29
3
votes
2 answers

Using group by in postgREST

I'm new to Postgres and postgREST. I would need to receive distinct records from one column - ideally with possibility to filter. Task I need to solve is in SQL select distinct "column1" where "column2" = "value2 and "column3" = "value3" column1,…
Bill
  • 63
  • 5
3
votes
3 answers

PostgREST / PostgreSQL Cannot enlarge string buffer message

I run into a Cannot enlarge string buffer message on my running postgREST API. I guess some tables are too large to work successful with the API. I am using the docker postgrest/postgrest container from https://hub.docker.com/r/postgrest/postgrest …
F.M.
  • 193
  • 2
  • 8
3
votes
1 answer

How to send a SIGHUP signal to PostgREST on Heroku from another Node.js program?

I have a PostgREST instance deployed on Heroku using the buildpack. The Postgres schemas are created by a Node.js program that uses node-pg-migrate. After the migrations have run, the schema is changed and PostgREST needs to reload the schema to…
Christiaan Westerbeek
  • 10,619
  • 13
  • 64
  • 89
2
votes
1 answer

How to escape string characters in supabase js OR query?

I'm trying to write a query that matches rows where a user-provided string matches one of two text array columns. For example, imagine a table messages with text columns greeting and goodbye: // WORKS const greeting = 'Hello there' const goodbye =…
2
votes
1 answer

How to use bigint safely with Supabase JS

Postgres' bigint type holds 64 bit integers. But the Supabase JS library returns those values as JS numbers, which cannot safely store 64 bit integers AFAIK. What would be the correct way to handle 64 bit integers in Supabase?
Sumit Ghosh
  • 1,033
  • 10
  • 29
2
votes
1 answer

How do you find table intersections in PostgREST clients?

Simple question from a rookie to PostgREST - is there an intersect function for the equivalent below PSQL query? select a from table1 intersect select a from table2; I read through the documentation https://postgrest.org/en/stable/ and didn't see…
walle
  • 21
  • 2
2
votes
2 answers

column-level security with policies in PostgreSQL 14 / PostgREST?

I'm using PostgREST as an API for a project and now implement the security functions. One thing I'd like to have but that is covered neither by row- nor by column-level security as I've read them so far is this use case: Table USERS is public…
Tom
  • 2,688
  • 3
  • 29
  • 53
2
votes
1 answer

How to disable anonymous execution of a postgrest query

Postgrest is rest API for postgreeSQL database. I am using postgrest v9.0.0 with the following config: db-uri = "postgres://remote_worker:1HyiYai@localhost:5432/myDb" db-schema = "public" db-anon-role = "remote_worker" jwt-secret =…
user2749279
  • 51
  • 1
  • 5
2
votes
2 answers

Is there a Postgrest API equivalent for MySQL?

I earlier worked on postgres sql database and created some functions there which i called using postgrest api via postman. I want to do the exact same thing with mysql, does this even possible?. Need to send get/post request by calling MySQL…
2
votes
1 answer

How to fix the Postgrest issue while fetching records

I am using PostgRest 8.0.0 and Postgres DB v14. I am facing the following error for selection of rows in a table. http://localhost:3000/table error: { "hint": null, "message": "invalid configuration parameter name…
2
votes
1 answer

PostgREST: disable direct access to everything but functions

I wonder if it's possible to deny access to all tables/views and only allow to functions? I just want to control the data I pass. I can't disable access with pg roles for the tables, cause the functions use the same tables. I can put on NGINX before…
Roman
  • 855
  • 1
  • 8
  • 15
2
votes
0 answers

postgrest swagger-ui setup documentation for all tables and views without giving anonymous user select permissions on the tables and views

I have a Postgres database where we have multiple tables and views. I have done Postgrest setup to expose it to the application. Along with the Postgrest API, I also have swagger which is working fine. Now in postgrest API, we have…
Ashok Rayal
  • 405
  • 3
  • 16
2
votes
1 answer

PostgREST custom function flat array instead of key:value

I have this custom function querying a group by from a datalist. As a result I receive my unique query result but as nested objects [{substance: 'value'}]. It would prefer my response to be [value, value, value]. SQL: create or replace function…
Hoetmaaiers
  • 3,413
  • 2
  • 19
  • 29
2
votes
0 answers

Convert JSONB to XML in Postgres

I've a table along the lines of CREATE TABLE documents ( id SERIAL PRIMARY KEY, author_id INTEGER NOT NULL FOREIGN KEY REFERENCES(author.id) content XML NOT NULL, created TIMESTAMP WITH TIMEZONE NOT NULL DEFAULT CURRENT_TIMESTAMP ) I want…
Algy Taylor
  • 814
  • 13
  • 29
1
2
3
9 10