Tag: postgresql 9.6

如何使用json插入非空列的表?

我试图用多个非空的默认列插入到food表中,命令如下: food_insertone('{"id": 1, "taste": "sweet"}'::JSON) food_insertone('{"id": 2}'::JSON) food_insertone('{"id": 3, "taste": null}'::JSON) 结果应该是这样的: INSERTED 1, 'sweet' INSERTED 2, '' ERROR (null not allowed in taste) 餐桌被定义为: CREATE TABLE "food" ( "id" INT, "taste" TEXT NOT NULL DEFAULT '', … ); CREATE OR REPLACE FUNCTION "food_insertone" (JSON) RETURNS VOID AS $$ INSERT INTO "food" SELECT * FROM […]

用knexjs创buildangular色

我是PostgreSQL和节点的新手。 我正在使用knex.js库。 我需要创buildangular色并将其分配给在PostgreSQL中创build的每个表。 我不知道我怎么能做到这一点。 是否在桌面迁移时完成? 或者我可以在迁移之后做到这一点? 如果是这样,我该怎么办呢?

为什么json_populate_record()不能识别行types?

我有2个表type和name 。 我试图通过一个函数与json_populate_record()插入到这些。 收到以下错误: first argument of json_populate_record must be a row type 表type创build使用: CREATE TABLE IF NOT EXISTS "type" ( "id" TEXT NOT NULL, "value" TEXT NOT NULL, PRIMARY KEY ("id"), CHECK ("id"<>'' AND "value"<>'') ); CREATE INDEX IF NOT EXISTS "idx_type_value" ON "type" ("value"); CREATE OR REPLACE FUNCTION "type_insertone" ( IN _a JSON […]