<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[PostgreSQL Projects - Medium]]></title>
        <description><![CDATA[Providing database solutions through postgres - Medium]]></description>
        <link>https://medium.com/postgresql-projects?source=rss----56d7f68efc10---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>PostgreSQL Projects - Medium</title>
            <link>https://medium.com/postgresql-projects?source=rss----56d7f68efc10---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 18:47:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/postgresql-projects" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Sql through Postgres — Django ORM without the ORM]]></title>
            <link>https://medium.com/postgresql-projects/sql-through-postgres-django-orm-without-the-orm-80af26331f5d?source=rss----56d7f68efc10---4</link>
            <guid isPermaLink="false">https://medium.com/p/80af26331f5d</guid>
            <category><![CDATA[django-orm]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[postgres]]></category>
            <dc:creator><![CDATA[Chukwunonso Nwafor]]></dc:creator>
            <pubDate>Wed, 25 Nov 2020 11:41:08 GMT</pubDate>
            <atom:updated>2020-11-25T11:49:39.784Z</atom:updated>
            <content:encoded><![CDATA[<h3>Sql through Postgres — Django ORM without the ORM</h3><p><strong><em>updated</em></strong> for <strong><em>python 3.85</em></strong>, <strong><em>postgreSQL 13.1</em></strong> and <strong><em>django 3.1.3</em></strong></p><p><em>Using Ubuntu as the default.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*JeCVbMsT17tWEwk05HkVxw.jpeg" /><figcaption>by Jordan Harrison — unsplash</figcaption></figure><h3>First Things First</h3><p>We create a folder, activate a <strong><em>virtual environment </em></strong>in it, get <strong><em>django</em></strong> and a <strong><em>postgres database connector </em></strong>(<strong><em>psycopg2</em></strong>) and finally create a django project in our folder. ( I am using Ubuntu on WSL2).</p><pre>sudo apt update<br>mkdir psq &amp;&amp; cd psq<br>python3 -m venv env &amp;&amp; source env/bin/activate<br>python3 -m pip install django psycopg2<br>django-admin startproject psq .</pre><p>Checking what was installed:</p><pre>python3 -m pip freeze</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/172/1*2FRelrxbjgju1l3cvZ5tcg.png" /><figcaption>installed apps for our project</figcaption></figure><h4>psq/settings.py</h4><p>Go to our <strong><em>settings.py</em></strong> file in folder <strong><em>psq</em></strong> and update our database connection settings as shown</p><pre>DATABASE = {<br>  &#39;default&#39;: {<br>    &#39;ENGINE&#39;: &#39;django.db.backends.postgresql&#39;,<br>    &#39;NAME&#39;: &#39;&lt;database name&gt;&#39;,<br>    &#39;USER&#39;: &#39;&lt;database user&gt;&#39;,<br>    &#39;PASSWORD&#39;: &#39;&lt;database password&gt;&#39;,<br>    &#39;HOST&#39;: &#39;localhost&#39;,<br>    &#39;PORT&#39;: &#39;5432&#39;,<br>  }<br>}</pre><p>Update your database name, user, password accordingly. Mine from <a href="https://medium.com/postgresql-projects/sql-through-postgres-introduction-aab67fd84b97"><em>Sql through Postgres — Introduction</em></a> is shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*rTsEOKz5UQDRKSi5nZ5QjQ.png" /><figcaption>database settings for project.</figcaption></figure><h3>Without Further Ado</h3><p>Django allows you to connect directly to your database, bypassing the ORM completely using <strong><em>django.db.connection</em></strong> or <strong><em>django.db.connections</em></strong> if you are using more than 1 database. Let’s give it a shot. (<strong><em>Ensure your postgresql server is running</em></strong>).</p><pre>python3 manage.py shell</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*QBwXCLwiH7laB41ljruLgA.png" /><figcaption>sample data definition</figcaption></figure><p>Cross checking if our table was created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*_Xs4evPYguL6bW_3dUHkcQ.png" /><figcaption>cross checking in another terminal</figcaption></figure><h4>Sample Data Manipulations and Queries</h4><p>We will work exclusively from the <strong><em>python shell</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*ZL3IGXQHws3nS7hq_38NyQ.png" /><figcaption>simple data manipulation and queries</figcaption></figure><p><strong>Perform more inserts</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*ZryQGm02iIOzI3JZWpR-6w.png" /><figcaption>more inserts.</figcaption></figure><p><strong>Return the largest sale of each user</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*cS7Yr0WO-o3y84EmrVRmKw.png" /><figcaption>queries on table `sales`</figcaption></figure><p><strong>Result</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*MwQbndtMfVxmHKirzpD8VA.png" /><figcaption>result from largest sales query</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80af26331f5d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/postgresql-projects/sql-through-postgres-django-orm-without-the-orm-80af26331f5d">Sql through Postgres — Django ORM without the ORM</a> was originally published in <a href="https://medium.com/postgresql-projects">PostgreSQL Projects</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL through Postgres — Introduction]]></title>
            <link>https://medium.com/postgresql-projects/sql-through-postgres-introduction-aab67fd84b97?source=rss----56d7f68efc10---4</link>
            <guid isPermaLink="false">https://medium.com/p/aab67fd84b97</guid>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[wsl-2]]></category>
            <dc:creator><![CDATA[Chukwunonso Nwafor]]></dc:creator>
            <pubDate>Mon, 16 Nov 2020 11:16:30 GMT</pubDate>
            <atom:updated>2020-11-16T11:20:53.247Z</atom:updated>
            <content:encoded><![CDATA[<h3>SQL through Postgres — Introduction</h3><p><strong><em>updated</em></strong> for <strong><em>postgreSQL</em></strong> 13.1</p><p><em>A million accolade for the world’s most advanced open source RDMS.</em></p><p><em>I love Microsoft’s Windows Subsystem for Linux.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*wBkujNp9G-IDxk5GZPygiw.jpeg" /><figcaption>by Carlos Muza — Unsplash</figcaption></figure><h3>Meet PostgreSQL</h3><p>PostgreSQL is a RDMS that follows the client/server model. The server can be on the same host with the client or not (in which case it accesses the server through a TCP/IP connection).</p><p><strong>Windows and Mac OS:</strong> Download and Install on Windows and Mac from <a href="https://www.enterprisedb.com/downloads/postgres-postgresql-downloads"><strong><em>EDB postgres</em></strong></a></p><p><strong>On Ubuntu (WSL2):</strong> To install postgreSQL (client &amp; server) on linux, we use the below code. <strong><em>postgresq-contrib</em></strong> installs additional extensions.</p><pre>sudo apt update<br>sudo apt install postgresql postgresql-contrib</pre><p>The above install creates a user account postgres and a database postgres we can use to connect to the postgreSQL server.</p><p>We check the status of the server and start it if need be.</p><pre>sudo service postgresql status</pre><p>If need be start the server with</p><pre>sudo service postgresql start</pre><p>PostgreSQL allows us to use the <strong><em>createdb</em></strong>, <strong><em>dropdb</em></strong>, <strong><em>createuser</em></strong> etc commands with a valid user account. Thus we create a new user.</p><pre>sudo -u postgres createuser --interactive</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/397/1*dclGYx7Z9JX_EefRVEIvkA.png" /><figcaption>creating new user</figcaption></figure><p>We connect using account <strong><em>postgres</em></strong> to set password for our new user <strong><em>guser</em></strong>.</p><pre>sudo -u postgres psql postgres</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*-oB7pE8Kvew0Uru0ihxF1w.png" /><figcaption>change user ‘guser’ password</figcaption></figure><p>Now we can create a new database from bash and assign <strong><em>guser</em></strong> as the owner.</p><pre>sudo -u postgres createdb gdb --owner guser</pre><p>We can now connect to postgreSQL server with ‘guser’ using our database.</p><pre>psql -h localhost -p 5432 -U guser -d gdb</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*hfGPWCTE9XXKlp8i-VFKng.png" /><figcaption>connected to guser with gdb</figcaption></figure><p>We can perform <strong><em>SQL</em></strong> and <strong><em>psql</em></strong> operations as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*I2VojWkQR4pwtfenXAXIvw.png" /><figcaption>example SQL and psql ops</figcaption></figure><p>We can exit <strong><em>psql</em></strong> using <strong><em>\q</em></strong> command.</p><p>To stop the server we use</p><pre>sudo service postgresql stop</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aab67fd84b97" width="1" height="1" alt=""><hr><p><a href="https://medium.com/postgresql-projects/sql-through-postgres-introduction-aab67fd84b97">SQL through Postgres — Introduction</a> was originally published in <a href="https://medium.com/postgresql-projects">PostgreSQL Projects</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>