我只想在表存在的情况下执行查询。如果表不存在
如果表不存在,请不要执行任何操作。
因此,我想检查表是否存在,然后检查表中是否有一些数据,如果有,请选择它们。
我想这/client.query("SELECT * FROM mytable", function(err,res) {
所以,我想是这样的:
client.query("do"+
" $$"+
"begin"+
" if (select count(*) from information_schema.columns" +
" where table_schema = 'public' " +
" and table_name = 'mytable')"+
" then "+
"DO NOTHING;"+
"else "+
"SELECT * FROM mytable;" +
"end if;"+
"end;"+
"$$"+
";", function(err, res) {
我不知道有关使用DO NOTHING
,而现在我收到error: syntax error at or near "NOTHING"
如果我使用NOT:
client.query("do"+
" $$"+
"begin"+
" if NOT (select count(*) = 0 from information_schema.columns" +
" where table_schema = 'public' " +
" and table_name = 'mytable')"+
" then "+
"SELECT * FROM mytable;" +
"end if;"+
"end;"+
"$$"+
";", function(err, res) {
Ιt工作时,表是空的,但是当我填写表中应做到select * from table
它抛出error: query has no destination for result data
你想从数据什么 –
@VaoTsun:当我点击(在我的程序上)“CheckMe”字段时,它会显示mytable中的所有字段。当它满了时会发生这种情况。当表为空时,我我得到一个错误(因为它是空的)。所以,我想避免这个。 – George
所以你想检查表是否存在,然后检查表中是否有一些数据,如果有一些你想选择它?..所有在一个过程 - 对吗? –