Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 如何将函数的结果用于insert语句?_Postgresql_Sql Insert - Fatal编程技术网

Postgresql 如何将函数的结果用于insert语句?

Postgresql 如何将函数的结果用于insert语句?,postgresql,sql-insert,Postgresql,Sql Insert,我有一个返回varchar的函数 CREATE OR REPLACE Function HashPassword(in p_email varchar, in p_password varchar) RETURNS TABLE( o_password varchar, o_user_id int ) as $$ return query select 'myresult', 9999; END $$ Language plpgsql; 我想对函数调用的结果表进行

我有一个返回varchar的函数

    CREATE OR REPLACE Function HashPassword(in p_email varchar, in p_password varchar)
RETURNS TABLE(
    o_password varchar,
    o_user_id int
) as
$$
    return query select 'myresult', 9999;
END
$$
Language plpgsql;
我想对函数调用的结果表进行插入

insert into table_that_needs_it(id, password, date)
select 99999, (select o_password from HashPassword('myemail', 'mypassword')), CURRENT_TIMESTAMP;
它给了我以下的错误

ERROR:  syntax error at or near ";"

仅使用一个选项:

insert into table_that_needs_it(id, password, date)
select 99999, o_password, CURRENT_TIMESTAMP
from hashpassword('myemail', 'mypassword');
如果您还想使用ID:

insert into table_that_needs_it(id, password, date)
select o_user_id, o_password, CURRENT_TIMESTAMP
from hashpassword('myemail', 'mypassword');

天哪,我真不敢相信我错过了。谢天谢地