<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>SQL on Lin's Blog</title><link>https://coder.tw/en/tags/sql/</link><description>Recent content in SQL on Lin's Blog</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Sun, 17 Sep 2017 13:39:48 +0000</lastBuildDate><atom:link href="https://coder.tw/en/tags/sql/index.xml" rel="self" type="application/rss+xml"/><item><title>BigQuery SQL String Split</title><link>https://coder.tw/en/posts/bigquery-sql-string-split/</link><pubDate>Sun, 17 Sep 2017 13:39:48 +0000</pubDate><guid>https://coder.tw/en/posts/bigquery-sql-string-split/</guid><description>&lt;p&gt;Most programmers are familiar with split. It&amp;rsquo;s one of the ten most commonly used functions in programming. BigQuery has a split function too, but since it&amp;rsquo;s SQL, the usage is quite different from general-purpose programming languages. On top of that, BigQuery comes in two versions, Standard SQL and Legacy SQL. Both have split, but they are used in completely different ways.&lt;/p&gt;</description></item><item><title>BigQuery SQL Get First or Last Day of Month From a Specified Date</title><link>https://coder.tw/en/posts/bigquery-sql-get-first-or-last-day-of-month-from-specify-date/</link><pubDate>Sat, 29 Jul 2017 18:38:56 +0000</pubDate><guid>https://coder.tw/en/posts/bigquery-sql-get-first-or-last-day-of-month-from-specify-date/</guid><description>&lt;p&gt;In BigQuery, if you want to get the first day from a date (or a timestamp or datetime value), for example turning &amp;ldquo;2017-05-24&amp;rdquo; into &amp;ldquo;2017-05-01&amp;rdquo;, you can call the UTC_USEC_TO_MONTH function in Legacy SQL, or DATE_TRUNC() in Standard SQL. In fact, BigQuery has a whole series of functions that do these things, getting the first day, hour, week, and so on from a date.&lt;/p&gt;</description></item><item><title>BigQuery SQL Get Random N Row Sampling</title><link>https://coder.tw/en/posts/bigquery-get-random-n-row-sampling-legacy-sql-standard-sql/</link><pubDate>Fri, 28 Jul 2017 23:57:37 +0000</pubDate><guid>https://coder.tw/en/posts/bigquery-get-random-n-row-sampling-legacy-sql-standard-sql/</guid><description>&lt;p&gt;When doing data analysis, randomly picking N rows from a dataset (sampling) is a very common need. You might sample to check whether the data is correct, or sample so a model can be built when there is too much data to process comfortably. Sampling with SQL inside the database is actually very simple. Here I&amp;rsquo;ll demonstrate with BigQuery Standard SQL, but Legacy SQL works the same way.&lt;/p&gt;</description></item><item><title>How to Defend Against Basic SQL Injection in PHP?</title><link>https://coder.tw/en/posts/php-basic-sql-injection-defense/</link><pubDate>Tue, 02 Aug 2011 07:00:27 +0000</pubDate><guid>https://coder.tw/en/posts/php-basic-sql-injection-defense/</guid><description>&lt;p&gt;&lt;a href="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/08/2011-08-01_222010.jpg"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: block; margin-left: auto; margin-right: auto; padding-top: 0px; border-width: 0px; border-color: initial; border-style: initial;" title="2011-08-01_222010" src="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/08/2011-08-01_222010_thumb.jpg" alt="2011-08-01_222010" width="524" height="401" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;For the past few days I&amp;rsquo;ve been writing a small program to organize contacts, so I&amp;rsquo;ve been researching quite a few things. While working on the database side, I wanted to guard against so-called SQL injection, where a malicious string is placed in a parameter to attack the database. So I applied some basic defenses. The following is how to add some basic protection against SQL injection~&lt;/p&gt;</description></item><item><title>How to Embed Arrays, $_POST, and $_GET Directly in a PHP String (SQL Query)</title><link>https://coder.tw/en/posts/php-embed-array-post-get-in-sql-string/</link><pubDate>Mon, 01 Aug 2011 14:23:03 +0000</pubDate><guid>https://coder.tw/en/posts/php-embed-array-post-get-in-sql-string/</guid><description>&lt;p&gt;Over the past few days, while writing a small program, I ran into a problem. I wanted to put a $_POST variable directly into my SQL query string instead of using the concatenation operator. But because of quoting issues, it took me quite a while to figure out how. Here is a brief introduction. I also want to thank Bu and Cang Shixian for teaching me this method! If it weren&amp;rsquo;t for them, I might still not know about it. Also, this method isn&amp;rsquo;t limited to $_POST; it works with other arrays too.&lt;/p&gt;</description></item><item><title>SQL Notes: The Difference Between the ` and ' Symbols</title><link>https://coder.tw/en/posts/sql-single-vs-double-quotes/</link><pubDate>Fri, 11 Feb 2011 10:43:48 +0000</pubDate><guid>https://coder.tw/en/posts/sql-single-vs-double-quotes/</guid><description>&lt;p&gt;&lt;a href="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/02/2010-07-27_233518.jpg"&gt;&lt;img class="alignnone size-large wp-image-206" title="2010-07-27_233518" src="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/02/2010-07-27_233518-540x259.jpg" alt="" width="432" height="207" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Recently, while writing a program in PHP, I ran into some SQL code, so I looked into it a bit and discovered something beginners easily get wrong: the &lt;strong&gt;`&lt;/strong&gt; and &lt;strong&gt;&amp;rsquo;&lt;/strong&gt; symbols do different things. When I didn&amp;rsquo;t know this, and the book&amp;rsquo;s print was small, it took me two hours to find out it was this small problem&amp;hellip;. So I wrote this post to tell everyone that these two really are different.&lt;/p&gt;</description></item></channel></rss>