exists

MySQL: Insert record if not exists in table

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to execute the following query: INSERT INTO table_listnames (name, address, tele) VALUES ('Rupert', 'Somewhere', '022') WHERE NOT EXISTS ( SELECT name FROM table_listnames WHERE name='value' ); But this returns an error. Basically I don't want to insert a record if the 'name' field of the record already exists in another record - how to check if the new name is unique? 回答1: I'm not actually suggesting that you do this, as the UNIQUE index as suggested by Piskvor and others is a far better way to do it, but you can actually do

Testing if a pandas DataFrame exists

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In my code, I have several variables which can either contain a pandas DataFrame or nothing at all. Let's say I want to test and see if a certain DataFrame has been created yet or not. My first thought would be to test for it like this: if df1: # do something However, that code fails in this way: ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). Fair enough. Ideally, I would like to have a presence test that works for either a DataFrame or Python None. Here is one way this can work:

insert into where not exists in hive

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I need the hive syntax for this equivalent in ansi sql insert into tablea ( id ) select id from tableb where id not in ( select id from tablea ) so tablea contains no duplicates and only new ids from tableb are inserted. 回答1: Use left outer join with a filter that the tablea.id is null: insert overwrite into tablea ( id ) select b . id from tableb b left outer join table tablea a on a . id = b . id where a . id is null 转载请标明出处: insert into where not exists in hive 文章来源: insert into where not exists in hive

How to check if a directory exists in Objective-C

匿名 (未验证) 提交于 2019-12-03 01:35:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I guess this is a beginner's problem, but I was trying to check if a directory exists in my Documents folder on the iPhone. I read the documentation and came up with this code which unfortunately crashed with EXC_BAD_ACCESS in the BOOL fileExists line: -(void)checkIfDirectoryAlreadyExists:(NSString *)name { NSFileManager *fileManager = [[NSFileManager alloc] init]; NSString *path = [[self documentsDirectory] stringByAppendingPathComponent:name]; BOOL fileExists = [fileManager fileExistsAtPath:path isDirectory:YES]; if (fileExists) { NSLog(@

Serve static files outside wwwroot, but handle PhysicalFileProvider when directory does not exist

匿名 (未验证) 提交于 2019-12-03 01:34:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying to serve files from outside wwwroot but also handle a setup situation where the directory may not exist yet. For example, if I built a site which relies on this directory, but a user did not follow install instructions and create the directory first. For the sake of argument, let's pretend I want a simple website which has a page that will read the contents of that directory and display some files. This page might also allow you to download files from /Documents subdirectory. The example directory would be C:\Example

'SET foreign_key_checks = 1' does not work again

匿名 (未验证) 提交于 2019-12-03 01:33:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am working with: mysql: stable 5.6.22 (bottled) MySQLWorkBench 6.2 I have the following sequence DROP TABLE IF EXISTS invoicedetail; DROP TABLE IF EXISTS invoiceheader; DROP TABLE IF EXISTS product; It fails when I work through Java (JDBC) and fails through the MySQLWorkBench too, the error message is about the FK Child constraints (I don't have the exact error message), well through Google I did a research and I have found the same valid solution twice. Cannot delete or update a parent row: a foreign key constraint fails How to

pytest (py.test) very slow startup in cygwin

匿名 (未验证) 提交于 2019-12-03 01:33:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: In cygwin, py.test starts up very slow. It does not look like a collection issue because of two reasons: The same test starts up quickly in linux. And sometimes, if rerun the same test fast enough in cygwin, it starts up in less than 1 second. Running through the time command tells it starts up in either 0.4 seconds, or 11.7 seconds, when supplied with the --collection-only option to avoid running the actual tests. I also added a print to the hooks pytest_configure() and pytest_ignore_collect() to be sure indeed it is before the

Writing to MySQL database with pandas using SQLAlchemy, to_sql

匿名 (未验证) 提交于 2019-12-03 01:33:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: trying to write pandas dataframe to MySQL table using to_sql. Previously been using flavor='mysql', however it will be depreciated in the future and wanted to start the transition to using SQLAlchemy engine. sample code: import pandas as pd import mysql . connector from sqlalchemy import create_engine engine = create_engine ( 'mysql+mysqlconnector://[user]:[pass]@[host]:[port]/[schema]' , echo = False ) cnx = engine . raw_connection () data = pd . read_sql ( 'SELECT * FROM sample_table' , cnx ) data . to_sql ( name = 'sample_table2

How to verify if a file exists in a DOS (Windows Command Prompt) .BAT file?

匿名 (未验证) 提交于 2019-12-03 01:33:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have to create a .BAT file that does this: If C:\myprogram\sync\data.handler exists, exit; If C:\myprogram\html\data.sql does not exist, exit; In C:\myprogram\sync\ delete all files and folders except ( test , test3 and test2 ) Copy C:\myprogram\html\data.sql to C:\myprogram\sync\ Call other batch file with option sync.bat myprogram.ini . If it was in the Bash environment it was easy for me, but I do not know how to test if a file or folder exists and if it is a file or folder. 回答1: You can use IF EXIST to check for a file: IF EXIST

check if SQL row exists with PHP

匿名 (未验证) 提交于 2019-12-03 01:33:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using MySQL with PHP and I need to do something like this (pseudocode): if (sql row exists where username='bob') { // do this stuff } 回答1: If you are using mysql database, then use the following - $query = "SELECT username from my_table where username='bob'"; $result = mysql_query($query); if(mysql_num_rows($result) > 0) { // row exists. do whatever you would like to do. } If you would like to use PDO (PHP Data Object) , as alex suggested, then use the following code - $dbh = new PDO("mysql:host=your_host_name;dbname=your_db_name", $user