exists

NodeJS + Mongo: Insert if not exists, otherwise - update

情到浓时终转凉″ 提交于 2019-12-23 06:49:05
问题 I have an object in my mongodb collection. Its schema is: { "instruments": ["A", "B", "C"], "_id": { "$oid": "508510cd6461cc5f61000001" } } My collection may have such object, but may not. I need to check if object with key "instruments" exists ( please, notе, I don't know what value "instrument" is at this time, it may contain any value or an array ), and if exists - perform update, otherwise – insert a new value. How can I do this? collection.find( { "instruments" : { $exists : true } },

Variables for identifiers inside IF EXISTS in a plpgsql function

本小妞迷上赌 提交于 2019-12-22 13:08:52
问题 CREATE OR REPLACE FUNCTION drop_now() RETURNS void AS $BODY$ DECLARE row record; BEGIN RAISE INFO 'in'; FOR row IN select relname from pg_stat_user_tables WHERE schemaname='public' AND relname LIKE '%test%' LOOP IF EXISTS(SELECT row.relname.tm FROM row.relname WHERE row.relname.tm < current_timestamp - INTERVAL '90 minutes' LIMIT 1) THEN -- EXECUTE 'DROP TABLE ' || quote_ident(row.relname); RAISE INFO 'Dropped table: %', quote_ident(row.relname); END IF; END LOOP; END; $BODY$ LANGUAGE plpgsql

Performance Comparation Between sql SELECT NULL and SELECT 1

会有一股神秘感。 提交于 2019-12-22 09:08:15
问题 Which one is better for performance IF EXISTS(Select null from table) or IF EXISTS(Select 1 from table) ? 回答1: Both perform the same, because the SELECT clause in the EXISTS is never evaluated. You can test using: ... EXISTS(SELECT 1/0 FROM TABLE) That should trigger a divide by zero error, but won't. I personally prefer using NULL because it's obvious that nothing is referenced in the table, so it's more visible to others. Selecting a value, like the INT number 1 in the second example, can

MySQL中EXISTS的用法

橙三吉。 提交于 2019-12-22 07:24:39
MySQL中EXISTS的用法 比如在Northwind数据库中有一个查询为 SELECT c.CustomerId,CompanyName FROM Customers c WHERE EXISTS( SELECT OrderID FROM Orders o WHERE o.CustomerID=c.CustomerID) 这里面的EXISTS是如何运作呢?子查询返回的是OrderId字段,可是外面的查询要找的是CustomerID和CompanyName字段,这两个字段肯定不在OrderID里面啊,这是如何匹配的呢? EXISTS用于检查子查询是否至少会返回一行数据,该子查询实际上并不返回任何数据,而是返回值True或False EXISTS 指定一个子查询,检测 行 的存在。 语法: EXISTS subquery 参数: subquery 是一个受限的 SELECT 语句 (不允许有 COMPUTE 子句和 INTO 关键字)。 结果类型: Boolean 如果子查询包含行,则返回 TRUE ,否则返回 FLASE 。 例表A:TableIn 例表B:TableEx (一). 在子查询中使用 NULL 仍然返回结果集 select * from TableIn where exists(select null) 等同于: select * from TableIn (二).

sql server操作2:查询数据库语句大全

让人想犯罪 __ 提交于 2019-12-22 04:22:33
注:以下操作均建立在上篇文章sql Server操作1的数据基础之上 一、实验目的 熟悉SQL语句的基本使用方法,学习如何编写SQL语句来实现查询 二、实验内容和要求 使用SQL查询分析器查询数据,练习查询语句的使用,掌握SELECT 语句的完整结构,包括简单查询、嵌套查询、连接查询等基本实现方法。 三、实验主要仪器设备和材料 1.计算机及操作系统:PC机,Windows 2000/xp/win7; 2.数据库管理系统:SQL sever 2005/2008; 四、实验方法、步骤及结果测试 实验题目: 1、对实验一建立的数据库表进行查询 简单查询: 1 题目1、查询学生的系别,用小写字母表示。 2 SQL语句 3 select distinct LOWER(Sdept) from S; 1 题目2、查询叫“刘%”的学生学号、系别 2 SQL语句 3 select Sno Sdept from S where Sname like '刘\%' escape'\'; 1 题目3、查询教师姓名第二个字是“一”的教师姓名,所教课程名。 2 SQL语句 3 select Tname,Cname from C where Tname like '_一_'; 1 题目4、查询没有成绩的学生学号,学号降序排列。 2 SQL语句 3 select S.Sno from S where not

有关存储过程的几个例子

我的梦境 提交于 2019-12-21 21:07:19
示例 A. 使用带有复杂 SELECT 语句的简单过程 下面的存储过程从四个表的联接中返回所有作者(提供了姓名)、出版的书籍以及出版社。该存储过程不使用任何参数。 USE pubs IF EXISTS (SELECT name FROM sysobjects WHERE name = au_info_all AND type = P) DROP PROCEDURE au_info_all GO CREATE PROCEDURE au_info_all AS SELECT au_lname, au_fname, title, pub_name FROM authors a INNER JOIN titleauthor ta ON a.au_id = ta.au_id INNER JOIN titles t ON t.title_id = ta.title_id INNER JOIN publishers p ON t.pub_id = p.pub_id GO au_info_all 存储过程可以通过以下方法执行: EXECUTE au_info_all -- Or EXEC au_info_all 如果该过程是批处理中的第一条语句,则可使用: au_info_all B. 使用带有参数的简单过程 下面的存储过程从四个表的联接中只返回指定的作者(提供了姓名)、出版的书籍以及出版社

dept_id int,

二次信任 提交于 2019-12-21 11:15:58
mysql - uroot - proot --default-character-set=gbk drop database if exists pro_db ; create database pro_db charset utf8 ; use pro_db ; drop table if exists projects ; create table projects ( id int primary key auto_increment , name varchar ( 30 ) unique not null ) ; drop table if exists emp ; create table emp ( id int primary key auto_increment , name varchar ( 20 ) not null , age int , marry char ( 2 ) , post varchar ( 20 ) default '中级程序员' , exp varchar ( 10 ) ) ; drop table if exists project_mapping ; create table project_mapping ( project_id int , emp_id int unique , foreign key ( project_id

detect if contact has photo

会有一股神秘感。 提交于 2019-12-20 21:23:34
问题 I've got an ImageView which I'm displaying a contacts picture using a Uri which always looks similar to this: content://com.android.contacts/contacts/34/photo How would I be able to detect whether this photo exists, as if it doesn't then I want to use a placeholder instead (stored in my drawable folder). At the moment it just shows a blank image. 回答1: a function to get a contacts photo uri: public Uri getPhotoUri(Integer contactid) { Cursor photoCur = getContentResolver().query

Correct PHP way to check if external image exists?

核能气质少年 提交于 2019-12-20 10:34:33
问题 I know that there are at least 10 the same questions with answers but none of them seems to work for me flawlessly. I'm trying to check if internal or external image exists (is image URL valid?). fopen($url, 'r') fails unless I use @fopen() : Warning: fopen(http://example.com/img.jpg) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in file.php on line 21 getimagesize($img) fails when image doesn't exist (PHP 5.3.8): Warning: getimagesize() [function

If url exists Objective-c

☆樱花仙子☆ 提交于 2019-12-20 10:20:53
问题 Hey, I have a program that needs to tell if an online image exists, but the only way that I've gotten this to work is by loading the image in a NSData pointer and checking if the pointer exists. - (BOOL)exists { NSString *filePath = @"http://couleeapps.hostei.com/BottomBox.png"; NSURL *url = [NSURL URLWithString:filePath]; NSData *imageData = [NSData dataWithContentsOfURL:url]; if (imageData) { return YES; } return NO; } This has worked for me, but my problem is that I have a very slow