使用postgresql和dart报错42601
Error 42601 using postgresql and dart
我在使用 postgresql 时收到错误 42601
我使用 pgAdmin 创建了 table。自动生成的代码如下所示。
-- 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 专家,所以这可能是我看不到的微不足道的东西。
您可以找到 postgresql here 的错误代码。错误42601表示语法错误。
我怀疑原因是您在 @flag.
之后的 'values' 子句中缺少右括号
我在使用 postgresql 时收到错误 42601
我使用 pgAdmin 创建了 table。自动生成的代码如下所示。
-- 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 专家,所以这可能是我看不到的微不足道的东西。
您可以找到 postgresql here 的错误代码。错误42601表示语法错误。
我怀疑原因是您在 @flag.
之后的 'values' 子句中缺少右括号