gpt4 book ai didi

Postgresql - 编辑函数签名

转载 作者:行者123 更新时间:2023-11-29 12:23:02 24 4
gpt4 key购买 nike

POSTGRESQL 8.4.3 - 我用这个签名创建了一个函数

创建或替换函数 logcountforlasthour() RETURNS SETOF 记录 AS

意识到我想把它改成这个

创建或替换函数 logcountforlasthour() RETURNS TABLE(ip bigint, count bigint) 记录为

但是当我在查询工具中应用该更改时,它没有被接受,或者更确切地说,它被接受,没有语法错误,但函数的文本没有改变。即使我在编辑之间运行“DROP FUNCTION logcountforlasthour()”,旧语法也会恢复

如果我编辑函数体,没关系,它会改变,但不会改变签名

有什么我想念的吗

谢谢

最佳答案

来自PostgreSQL 8.4 manual :

To replace the current definition of an existing function, use CREATE OR REPLACE FUNCTION. It is not possible to change the name or argument types of a function this way (if you tried, you would actually be creating a new, distinct function). Also, CREATE OR REPLACE FUNCTION will not let you change the return type of an existing function. To do that, you must drop and recreate the function. (When using OUT parameters, that means you cannot change the names or types of any OUT parameters except by dropping the function.)

If you drop and then recreate a function, the new function is not the same entity as the old; you will have to drop existing rules, views, triggers, etc. that refer to the old function. Use CREATE OR REPLACE FUNCTION to change a function definition without breaking objects that refer to the function. Also, ALTER FUNCTION can be used to change most of the auxiliary properties of an existing function.

The user that creates the function becomes the owner of the function.

同时注意:

... PostgreSQL allows function overloading; that is, the same name can be used for several different functions so long as they have distinct argument types.

关于Postgresql - 编辑函数签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2811196/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com