我有一个带有两个参数的函数,第一个是整数,第二个是varchars数组。
我只想插入之前未为广告系列插入的哈希值,然后返回插入的ID(在这种情况下,返回class NameForm extends React.Component {
constructor(props) {
super(props);
this.state = {value: ''};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
this.setState({value: event.target.value});
}
handleSubmit(event) {
alert('A name was submitted: ' + this.state.value);
event.preventDefault();
}
render() {
return (
<form onSubmit={this.handleSubmit}>
<label>
Name:
<input type="text" value={this.state.value} onChange={this.handleChange} />
</label>
<input type="submit" value="Submit" />
</form>
);
}
}
表的url_hash
字段),但我一直在以下错误:
campaigns_urls
我正在调用这样的函数:
ERROR: column "hash" does not exist LINE 10: RETURNING "hash"
^
HINT: There is a column named "hash" in table "*SELECT*", but it cannot be referenced from this part of the query.
答案 0 :(得分:1)
还有更多问题:
如果函数返回多行,则应在SETOF
之后使用RETURNS
关键字。
PlpgSQL函数需要RETURN
语句-在这种情况下为RETURN QUERY
。
create table test(a int);
create or replace function foo(int)
returns setof int as $$
begin
return query
insert into test
select v from generate_series(1,$1) g(v)
returning a;
end;
$$ language plpgsql;
postgres=# select * from foo(3);
┌─────┐
│ foo │
╞═════╡
│ 1 │
│ 2 │
│ 3 │
└─────┘
(3 rows)