Postgrest: Create tables dynamically and bind foreign keys? Unable to query data

Created on 3 Jun 2019  ·  2Comments  ·  Source: PostgREST/postgrest

Environment

  • PostgreSQL 9.5
  • PostgREST 5.2
  • Operating system: win7 x64

Description of issue ,step

  1. There is a stored procedure that creates tables based on SQL statements and passes them by array。
    for example
  2. sql---companys
    CREATE TABLE public.companys
    (
    id uuid NOT NULL,
    status boolean,
    "companyName" character varying(128) COLLATE pg_catalog."default",
    "legPerson" character varying(128) COLLATE pg_catalog."default",
    email character varying(100) COLLATE pg_catalog."default",
    "projectName" character varying(128) COLLATE pg_catalog."default",
    "powerName" character varying(128) COLLATE pg_catalog."default",
    "roleName" character varying(128) COLLATE pg_catalog."default",
    "deptName" character varying(128) COLLATE pg_catalog."default",
    "userRole" character varying(128) COLLATE pg_catalog."default",
    "userDept" character varying(128) COLLATE pg_catalog."default",
    "rolePower" character varying(128) COLLATE pg_catalog."default",
    phone character varying(64) COLLATE pg_catalog."default",
    CONSTRAINT companys_pkey PRIMARY KEY (id)
    )
    2.sql--users (There is a foreign key binding relationship)
    CREATE TABLE public.users
    (
    id uuid NOT NULL,
    "userName" character varying(40) COLLATE pg_catalog."default",
    "userPassword" character varying(200) COLLATE pg_catalog."default",
    phone character varying(40) COLLATE pg_catalog."default",
    email character varying(100) COLLATE pg_catalog."default",
    "companyName" character varying(80) COLLATE pg_catalog."default",
    "companyId" uuid,
    note text COLLATE pg_catalog."default",
    CONSTRAINT users_pkey PRIMARY KEY (id),
    CONSTRAINT "users_companyId_fkey" FOREIGN KEY ("companyId")
    REFERENCES public.companys (id) MATCH SIMPLE
    ON UPDATE NO ACTION
    ON DELETE NO ACTION
    )
  3. post ip:port/create_table
    {
    companys,users
    }

  4. qurey data by get /users?select=,companys()

{
"message": "Could not find foreign keys between these entities, No relation found between users and users"
}
4.If the service is restarted, everything will be fine,why? is bug or not support?tell me
thanks。

Most helpful comment

PostgREST caches the database schema on startup, and doesn't refresh the cache. So, PostgREST doesn't know about the new tables you created with that sproc.

See here in the docs for more details

All 2 comments

PostgREST caches the database schema on startup, and doesn't refresh the cache. So, PostgREST doesn't know about the new tables you created with that sproc.

See here in the docs for more details

=

PostgREST caches the database schema on startup, and doesn't refresh the cache. So, PostgREST doesn't know about the new tables you created with that sproc.

See here in the docs for more details

Sorry, it took so long to reply. Thank you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Chaz6 picture Chaz6  ·  4Comments

blainehansen picture blainehansen  ·  4Comments

NickEmpetvee picture NickEmpetvee  ·  4Comments

priyank-purohit picture priyank-purohit  ·  3Comments

ACPK picture ACPK  ·  5Comments