I wrote a SQL at work today, but PostgreSQL always prompts for grammatical errors and makes a simple record:
question 1, "and" "single and double quotes As an example:
1 #1、select id, delivery_date, sal_plan_date from zaiko_shop where id="";
2 #2、select id, delivery_date, sal_plan_date from zaiko_shop where id=‘‘;
The above two sentences of different knowledge of SQL # is used in double quotes, #2用的是单引号 but will be error: The above problem prompts us to write SQL statements as much as possible: the outermost use of double quotation marks, the concatenation of an SQL statement, the string conditions in the SQL statement to make Use single quotation marks$sql = "SELECT ID, delivery_date, sal_plan_date from Zaiko_shop where id= '"Question 2, null and ' ' For example:
1 SELECT COUNT(*) AS adv_num
2 FROM zaiko_shop
3 WHERE delivery_date!=null
4 AND sal_plan_date != null
5 AND to_char(delivery_date,‘YYYY-MM‘) != to_char(sal_plan_date,‘YYYY-MM‘)
6 AND shop_id=1031
7 AND del_flag=0
8 AND sal_plan_date BETWEEN ‘2014-01-01‘ AND ‘2014-12-31‘;
The first is to judge the date type as empty? The above writing is wrong, turn to some of the previous learning MySQL is the note, you can make a reference, after all, is the same place in SQL or there are a lot ofFirst, we should be clear: what is the difference between null and '? "It's like you have a bank card in the bank, but there's no money in it.null equals you don't have a bank card at all, some basic descriptive information is notsecond, for sal_plan_date! = null Here's!=nullNULL is a type that can be compared using only specialized is NULL or is not NULL to compareWhen you encounter an operator, you return null, for example: where Name!=null, which is not getting the data we expect or can't get the correct data .
Therefore, the above is the wrong way of writing, although the above is a small problem, but sometimes these small problems, let us ' very top ', so, the normal use of norms, can avoid a lot of troublesome things. Will let us less go to a lot of headache time, otherwise, the hair on the table to see themselves are sad, before that the programmer bald is nonsense, now feel this is indeed possible, because I usually very annoying when the hair after pulling, hey 、、、 so, the specification of the writing help us in imperceptible can reduce a lot of trouble! Make a record, hoping to help others!
Quotation marks and Null in PostgreSQL