avatarJoshua Otwell

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2215

Abstract

MySQL SELECT INTO Syntax Part 3 — DUMPFILE with examples</a></li></ul><p id="4e4e">For the example queries in this post, I’ll use a couple of tables from the <a href="http://www.postgresqltutorial.com/postgresql-sample-database/">PostgreSQL practice DVD Rental database</a>.</p><p id="fdf7">Suppose I have this query that returns all columns for any cities that start with ‘Z’:</p><div id="9204"><pre>dvdrental=> SELECT * FROM city WHERE city LIKE ‘Z%’; city_id | <span class="hljs-type">city</span> | <span class="hljs-type">country_id</span> | <span class="hljs-type">last_update</span> — — — — -+ — — — — — — — + — — — — — — + — — — — — — — — — — - <span class="hljs-number">592</span> | <span class="hljs-type">Zalantun</span> | <span class="hljs-type">23</span> | <span class="hljs-type">2006</span><span class="hljs-number">02</span><span class="hljs-number">15</span> <span class="hljs-number">09</span>:<span class="hljs-number">45</span>:<span class="hljs-number">25</span> <span class="hljs-number">593</span> | <span class="hljs-type">Zanzibar</span> | <span class="hljs-type">93</span> | <span class="hljs-type">2006</span><span class="hljs-number">02</span><span class="hljs-number">15</span> <span class="hljs-number">09</span>:<span class="hljs-number">45</span>:<span class="hljs-number">25</span> <span class="hljs-number">594</span> | <span class="hljs-type">Zaoyang</span> | <span class="hljs-type">23</span> | <span class="hljs-type">2006</span><span class="hljs-number">02</span><span class="hljs-number">15</span> <span class="hljs-number">09</span>:<span class="hljs-number">45</span>:<span class="hljs-number">25</span> <span class="hljs-number">595</span> | <span class="hljs-type">Zapopan</span> | <span class="hljs-type">60</span> | <span class="hljs-type">2006</span><span class="hljs-number">02</span><span class="hljs-number">15</span> <span class="hljs-number">09</span>:<span class="hljs-number">45</span>:<span class="hljs-number">25</span> <span class="hljs-number">596</span> | <span class="hljs-type">Zaria</span> | <span class="hljs-type">69</span>

Options

| <span class="hljs-type">2006</span><span class="hljs-number">02</span><span class="hljs-number">15</span> <span class="hljs-number">09</span>:<span class="hljs-number">45</span>:<span class="hljs-number">25</span> <span class="hljs-number">597</span> | <span class="hljs-type">Zeleznogorsk</span> | <span class="hljs-type">80</span> | <span class="hljs-type">2006</span><span class="hljs-number">02</span><span class="hljs-number">15</span> <span class="hljs-number">09</span>:<span class="hljs-number">45</span>:<span class="hljs-number">25</span> <span class="hljs-number">598</span> | <span class="hljs-type">Zhezqazghan</span> | <span class="hljs-type">51</span> | <span class="hljs-type">2006</span><span class="hljs-number">02</span><span class="hljs-number">15</span> <span class="hljs-number">09</span>:<span class="hljs-number">45</span>:<span class="hljs-number">25</span> <span class="hljs-number">599</span> | <span class="hljs-type">Zhoushan</span> | <span class="hljs-type">23</span> | <span class="hljs-type">2006</span><span class="hljs-number">02</span><span class="hljs-number">15</span> <span class="hljs-number">09</span>:<span class="hljs-number">45</span>:<span class="hljs-number">25</span> <span class="hljs-number">600</span> | <span class="hljs-type">Ziguinchor</span> | <span class="hljs-type">83</span> | <span class="hljs-type">2006</span><span class="hljs-number">02</span><span class="hljs-number">15</span> <span class="hljs-number">09</span>:<span class="hljs-number">45</span>:<span class="hljs-number">25</span> (<span class="hljs-number">9</span> rows)</pre></div><p id="a1cb">Arbitrarily, imagine we need a PLpgSQL function to return the ‘country_id’ column value for the above query. That function could be written as the following:</p><p id="6167"><a href="https://joshuaotwell.com/the-strict-keyword-with-select-into-examples-in-postgresql/">Continue reading the full post here…</a></p><p id="9a60"><i>Originally published at <a href="https://joshuaotwell.com/the-strict-keyword-with-select-into-examples-in-postgresql/">https://joshuaotwell.com</a> on June 26, 2019.</i></p></article></body>

The STRICT keyword with SELECT INTO — examples in PostgreSQL

In concert with writing quality open-source SQL blog posts, I have developed a yearning to become a well-versed PostgreSQL PLpgSQL programmer. What a perfect opportunity to share what I learn about PLpgSQL, on my blog, while building solid SQL skills. In this post, I will cover the clause as part of a PLpgSQL function, focusing on the keyword for even more fine-tuned functionality.

Photo by Samuel Zeller on Unsplash

Note: All data, names or naming found within the database presented in this post, are strictly used for practice, learning, instruction, and testing purposes. It by no means depicts actual data belonging to or being used by any party or organization.

OS and DB used:

  • Xubuntu Linux 18.04.2 LTS (Bionic Beaver)
  • PostgreSQL 11.2

Self-Promotion:

If you enjoy the content written here, by all means, share this blog and your favorite post(s) with others who may benefit from or like it as well. Since coffee is my favorite drink, you can even buy me one if you would like!

Although I targeted a different SQL dialect, I wrote 3 fantastic blog posts exploring I’d love for you to read. Feel free to visit them each in turn below.

For the example queries in this post, I’ll use a couple of tables from the PostgreSQL practice DVD Rental database.

Suppose I have this query that returns all columns for any cities that start with ‘Z’:

dvdrental=> SELECT * FROM city WHERE city LIKE ‘Z%’;
 city_id  | city          | country_id  | last_update 
 — — — — -+ — — — — — — — + — — — — — — + — — — — — — — — — — -
 592      | Zalantun      | 23          | 20060215 09:45:25
 593      | Zanzibar      | 93          | 20060215 09:45:25
 594      | Zaoyang       | 23          | 20060215 09:45:25
 595      | Zapopan       | 60          | 20060215 09:45:25
 596      | Zaria         | 69          | 20060215 09:45:25
 597      | Zeleznogorsk  | 80          | 20060215 09:45:25
 598      | Zhezqazghan   | 51          | 20060215 09:45:25
 599      | Zhoushan      | 23          | 20060215 09:45:25
 600      | Ziguinchor    | 83          | 20060215 09:45:25
(9 rows)

Arbitrarily, imagine we need a PLpgSQL function to return the ‘country_id’ column value for the above query. That function could be written as the following:

Continue reading the full post here…

Originally published at https://joshuaotwell.com on June 26, 2019.

Sql
Postgresql
Postgres
Database
Database Development
Recommended from ReadMedium