我如何让我的 PostgresQL 成功执行调用?
How do i get my PostgresSQL to perform the Call Succesfully?
过去一周我一直在为此绞尽脑汁,这是一个插入存储过程,我将在应用程序中使用它来输入库存信息。出于某种原因,我不断收到相同的错误,即使我相信我正在按照文档流程来执行此操作。我做错了什么?
我对这个过程的思考过程是,我将定义应用程序将输入的变量,然后将这些变量的值分配到 table 中的列中。
这是我的程序:
CREATE OR REPLACE PROCEDURE public.add_inventory(
_inventory_name character varying,
_brand character varying,
_category character varying,
_color character varying,
_inventory_size character varying,
_image_link character varying,
_sku character varying,
_date_added date,
_list_price money,
_row_status integer DEFAULT 1)
LANGUAGE 'plpgsql'
AS $BODY$
begin
Insert into dbo.inventory_tb
(inventory_name, brand, category, color, inventory_size, image_link, sku, date_added, list_price, row_status)
values
(_inventory_name, _brand, _category, _color, _inventory_size, _image_link, _sku, _date_added, _list_price, _row_status);
end;
$BODY$;
GRANT EXECUTE ON PROCEDURE public.add_inventory(character varying, character varying, character varying, character varying, character varying, character varying, character varying, date, money, integer) TO PUBLIC;
我尝试通过查询编辑器提交但未成功的“呼叫”如下:
CALL public.add_inventory(
'Specs',
'Gracia1',
'Shirt1',
'Red1',
'Small',
'rootfile',
'00001',
'2021-03-31',
60.00,
1
)
我得到的错误是:
LINE 1: CALL public.add_inventory(
^
HINT: No procedure matches the given name and argument types. You might need to add explicit type casts.
SQL state: 42883
Character: 6
我插入这个信息的table是这样的:
CREATE TABLE public.inventory_tb
(
inventory_id integer NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
inventory_name character varying(100) COLLATE pg_catalog."default" NOT NULL,
brand character varying(100) COLLATE pg_catalog."default" NOT NULL,
category character varying(100) COLLATE pg_catalog."default" NOT NULL,
color character varying(100) COLLATE pg_catalog."default" NOT NULL,
date_added date NOT NULL,
inventory_size character varying(50) COLLATE pg_catalog."default" NOT NULL,
list_price money NOT NULL,
image_link character varying(100) COLLATE pg_catalog."default" NOT NULL,
sku character varying(100) COLLATE pg_catalog."default" NOT NULL,
row_status integer NOT NULL,
CONSTRAINT "inventory_tb_PK" PRIMARY KEY (inventory_id)
)
TABLESPACE pg_default;
ALTER TABLE public.inventory_tb
OWNER to postgres;
删除旧过程并将其定义为使用相应类型类别的首选数据类型:
CREATE OR REPLACE PROCEDURE public.add_inventory(
_inventory_name text,
_brand text,
_category text,
_color text,
_inventory_size text,
_image_link text,
_sku text,
_date_added date,
_list_price numeric,
_row_status integer DEFAULT 1
) LANGUAGE plpgsql AS
$BODY$
BEGIN
INSERT INTO dbo.inventory_tb
(inventory_name, brand, category, color, inventory_size, image_link, sku, date_added, list_price, row_status)
VALUES
(_inventory_name, _brand, _category, _color, _inventory_size, _image_link, _sku, _date_added, _list_price, _row_status);
END;
$BODY$;
那么PostgreSQL就可以根据type conversion rules隐式转换数据类型,不需要显式类型转换。
数据类型与 table 中的数据类型略有不同并不重要,因为 PostgreSQL 将在赋值时应用类型转换。
现在通话正常:
CALL public.add_inventory(
'Specs',
'Gracia1',
'Shirt1',
'Red1',
'Small',
'rootfile',
'00001',
'2021-03-31',
60.00,
1
);
CALL
过去一周我一直在为此绞尽脑汁,这是一个插入存储过程,我将在应用程序中使用它来输入库存信息。出于某种原因,我不断收到相同的错误,即使我相信我正在按照文档流程来执行此操作。我做错了什么?
我对这个过程的思考过程是,我将定义应用程序将输入的变量,然后将这些变量的值分配到 table 中的列中。 这是我的程序:
CREATE OR REPLACE PROCEDURE public.add_inventory(
_inventory_name character varying,
_brand character varying,
_category character varying,
_color character varying,
_inventory_size character varying,
_image_link character varying,
_sku character varying,
_date_added date,
_list_price money,
_row_status integer DEFAULT 1)
LANGUAGE 'plpgsql'
AS $BODY$
begin
Insert into dbo.inventory_tb
(inventory_name, brand, category, color, inventory_size, image_link, sku, date_added, list_price, row_status)
values
(_inventory_name, _brand, _category, _color, _inventory_size, _image_link, _sku, _date_added, _list_price, _row_status);
end;
$BODY$;
GRANT EXECUTE ON PROCEDURE public.add_inventory(character varying, character varying, character varying, character varying, character varying, character varying, character varying, date, money, integer) TO PUBLIC;
我尝试通过查询编辑器提交但未成功的“呼叫”如下:
CALL public.add_inventory(
'Specs',
'Gracia1',
'Shirt1',
'Red1',
'Small',
'rootfile',
'00001',
'2021-03-31',
60.00,
1
)
我得到的错误是:
LINE 1: CALL public.add_inventory(
^
HINT: No procedure matches the given name and argument types. You might need to add explicit type casts.
SQL state: 42883
Character: 6
我插入这个信息的table是这样的:
CREATE TABLE public.inventory_tb
(
inventory_id integer NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
inventory_name character varying(100) COLLATE pg_catalog."default" NOT NULL,
brand character varying(100) COLLATE pg_catalog."default" NOT NULL,
category character varying(100) COLLATE pg_catalog."default" NOT NULL,
color character varying(100) COLLATE pg_catalog."default" NOT NULL,
date_added date NOT NULL,
inventory_size character varying(50) COLLATE pg_catalog."default" NOT NULL,
list_price money NOT NULL,
image_link character varying(100) COLLATE pg_catalog."default" NOT NULL,
sku character varying(100) COLLATE pg_catalog."default" NOT NULL,
row_status integer NOT NULL,
CONSTRAINT "inventory_tb_PK" PRIMARY KEY (inventory_id)
)
TABLESPACE pg_default;
ALTER TABLE public.inventory_tb
OWNER to postgres;
删除旧过程并将其定义为使用相应类型类别的首选数据类型:
CREATE OR REPLACE PROCEDURE public.add_inventory(
_inventory_name text,
_brand text,
_category text,
_color text,
_inventory_size text,
_image_link text,
_sku text,
_date_added date,
_list_price numeric,
_row_status integer DEFAULT 1
) LANGUAGE plpgsql AS
$BODY$
BEGIN
INSERT INTO dbo.inventory_tb
(inventory_name, brand, category, color, inventory_size, image_link, sku, date_added, list_price, row_status)
VALUES
(_inventory_name, _brand, _category, _color, _inventory_size, _image_link, _sku, _date_added, _list_price, _row_status);
END;
$BODY$;
那么PostgreSQL就可以根据type conversion rules隐式转换数据类型,不需要显式类型转换。
数据类型与 table 中的数据类型略有不同并不重要,因为 PostgreSQL 将在赋值时应用类型转换。
现在通话正常:
CALL public.add_inventory(
'Specs',
'Gracia1',
'Shirt1',
'Red1',
'Small',
'rootfile',
'00001',
'2021-03-31',
60.00,
1
);
CALL