使用postgresql
时出现错误42601我使用pgAdmin创建了表。自动生成的代码如下所示。
-- Table: posts
-- DROP TABLE posts;
CREATE TABLE posts
(
post_id bigserial NOT NULL,
title character varying(150) NOT NULL,
description character varying(500),
posted_at timestamp with time zone,
last_edited timestamp with time zone,
"user" character varying(50) NOT NULL,
editor character varying(50),
up_votes integer NOT NULL,
down_votes integer NOT NULL,
flag character varying(7),
CONSTRAINT "PK_post_id" PRIMARY KEY (post_id),
CONSTRAINT "FK_user" FOREIGN KEY ("user")
REFERENCES users (login) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE posts
OWNER TO postgres;
我使用以下辅助方法执行插入操作。
addPost(Map values){
connect(uri)
.then((conn){
conn.execute('insert into posts values(@title, @description, now(), now(), @user, @editor, @upVotes, @downVotes, @flag', values)
.then((_) => conn.close())
.catchError((err){
print('Execute error in addPost: $err');
})
.whenComplete(() => conn.close());
})
.catchError((err) => print('Error in addPost: $err'));
}
其中Map values
的格式为:
{'title': 'Sample title', 'description': 'This is a description for a sample post', 'user': 'dartUser', 'editor': 'dartUser', 'upVotes': 0, 'downVotes': 0, 'flag': 'healthy'}
我不是postgresql专家,所以这可能是一件微不足道的事我只是不知道。