PostgREST - 如何创建表?
PostgREST - How to create tables?
我想使用 postgREST 创建一个新的 table,但我无法在文档中找到任何相关信息。是否可以创建 tables?如果是,如何?
抱歉,如果这个问题已经被问过,但不幸的是我总是找到 postgres 的解决方案(没有 t :D)
谢谢:)
您可以创建为您创建 table 的存储函数,然后通过 postgrest
调用该函数
类似于:
create or replace function create_foo_table() returns void as
$$
begin
execute format('create table foo (id int primary key)')
end
$$ language plpgsql;
然后在 Postgrest
中调用 /rpc/create_foo_table
之后您需要重新加载 Postgrest 的模式缓存,以便读取 table:https://postgrest.org/en/v7.0.0/admin.html?highlight=reload#schema-reloading
这可能有安全隐患,所以要小心,特别是如果使用动态 SQL 创建 table
我想使用 postgREST 创建一个新的 table,但我无法在文档中找到任何相关信息。是否可以创建 tables?如果是,如何?
抱歉,如果这个问题已经被问过,但不幸的是我总是找到 postgres 的解决方案(没有 t :D)
谢谢:)
您可以创建为您创建 table 的存储函数,然后通过 postgrest
调用该函数类似于:
create or replace function create_foo_table() returns void as
$$
begin
execute format('create table foo (id int primary key)')
end
$$ language plpgsql;
然后在 Postgrest
中调用/rpc/create_foo_table
之后您需要重新加载 Postgrest 的模式缓存,以便读取 table:https://postgrest.org/en/v7.0.0/admin.html?highlight=reload#schema-reloading
这可能有安全隐患,所以要小心,特别是如果使用动态 SQL 创建 table