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
0
votes
0 answers

how to copy the tables of influx db ( free versione ) into postgres

project-schema As you see in the pictures I have this kind of schema, project-schema I'll have many "measurements" (tables) into influxdb, that I need to copy into Postgresdb, so my django app will query the local copy instead of influxdb. i really…
daner
  • 1
  • 2
0
votes
1 answer

how to create Postgresql Http query request

I am new to PostgreSQL and wanted to know if it's possible to create a http link for selecting a particular data from the table. I tried working with Postgres but can't really follow the documentation. The docker and postgREST container is running…
shruti
  • 1
  • 2
0
votes
1 answer

Json parameter in POSTMAN with postgreSQL function

I have created the postgreSQL function below: create or replace function analyse_lat(jsonvariable json) returns table (ok boolean, nb text) as $BODY$ declare r record; begin for r in (select * from json_to_recordset(jsonvariable->'list')…
MyJobIsHard
  • 25
  • 1
  • 6
0
votes
1 answer

Can't get my URL parameters to match my API call to postgres

I'm using postgrest as an API wrapper to my postgres db. The api reads my database schema and creates URL using common characters in the address. I have a function like so = create function api.dividend(p_stocks text[]) A general API…
andres
  • 1,558
  • 7
  • 24
  • 62
0
votes
1 answer

Best way to embed JSON fields in POST requests for insert into PG using PostgREST

I am using PostgREST 7 and would like to do a simple insert into PostgreSQL. One of my fields is a JSON string and inserting it into the JSON body of the request breaks the parsing on PostgREST. As an example using a simple JSON field, a request…
0
votes
0 answers

Error: Unable to call postgres function in CURL GET request

I have a custom function in my remote PostgreSQL/PostGIS database that finds the nearest linestring based on the given coordinates (lon, lat in CRS: 4326). I am on Windows 10 (x64 machine) and using PostgREST API to make my curl request talk to the…
khajlk
  • 791
  • 1
  • 12
  • 32
0
votes
1 answer

Nested embedded resources

I'm new to postgREST. I've set it up and it's working fine with my db. I'm going through the docs and I think I could use of Resource Embedding, but I can't figure out how to make it work in a nested way. My schema has tables similar to the…
Awer Muller
  • 557
  • 7
  • 17
0
votes
0 answers

Handling files with Postgrest

I am currently developing a webapp and a feature is for the user to be able to download invoices and product info in the form of pdfs. Right now i am using base64 as text and sending it through the API. Is this bad practice, and if so are there any…
0
votes
1 answer

anyone successfully implemented SQL User management with PostgRest and Postgresql?

I am trying to implement SQL User Management with PostgREST and PostgreSQL. Official PostgRest documentation http://postgrest.org/en/v5.2/auth.html#sql-user-management helped me put together the following: create schema if not exists…
haytham
  • 502
  • 4
  • 22
0
votes
1 answer

postgrest retreive ranked results

I made a game, with level and scores saved into an sql table like this : create table if not exists api.scores ( id serial primary key, pseudo varchar(50), level int, score int, created_at timestamptz default CURRENT_TIMESTAMP ); I want to display…
C Taque
  • 997
  • 2
  • 15
  • 31
0
votes
1 answer

How to use a second docker instance?

Assuming that the command for a second docker instance is docker run --rm --net=host -p 3002:3002 -e SERVER_PORT="3002" \ -e PGRST_DB_URI="postgres://postgres@localhost/prod2" \ -e PGRST_DB_ANON_ROLE="postgres" postgrest/postgrest it…
Peter Krauss
  • 13,174
  • 24
  • 167
  • 304
0
votes
1 answer

how to get array in database column ? Laravel

I want to get array in database,it work in database query (my database i use postgrest) but not work in my project laravel. Error message -> Undefined column: 7 ERROR: column sample1.text[1] does not exist table…
0
votes
1 answer

Postgresql v12 Function returns Function Name in Json

This is the required query result from a function: [{"id":1,"task":"Finish Task ONE"},{"id":2,"task":"Finish Task TWO"}] And it is produced correctly in pgAdmin4 by: SELECT api.add_them(1,2) in 4. However, when the function is invoked with…
Nasher
  • 1
0
votes
1 answer

Is there any way to get table metadata using postgREST

I need to get table metadata like primary key, column type etc. using PostgRest. By executing the root path / of my PostgRest app I am getting JSON that contains all needed data in definitions object. Unfortunately there is no endpoint to get it…
0
votes
1 answer

Postgrest OR query with JSON

I have a json query I'm making with postgrest, that I need to accept 2 scenarios. either the value has to be equal to "failover" or it's null (doesn't exist). If there wasn't JSON involved, this would be a simple…
MLyck
  • 4,959
  • 13
  • 43
  • 74