我试图使用准备好的语句将值插入数据库,但是有时我需要为特定值插入文字'DEFAULT',我该怎么做?
CREATE TABLE test (id int,firstname text default 'john',lastname text default 'doe');
这是我想要做的,但是使用准备好的语句:
insert into test (id,firstname,lastname) VALUES ('1',DEFAULT,DEFAULT);
但这会导致错误(出于明显的原因):
PREPARE testprep (integer,text,text) AS INSERT INTO test (id,lastname) VALUES ($1,$2,$3);
EXECUTE testprep('1',DEFAULT);
错误:
ERROR: syntax error at or near "DEFAULT"
我使用SQL-Fiddle创建的两个示例: