<?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[Stories by Sapna Chatrani on Medium]]></title>
        <description><![CDATA[Stories by Sapna Chatrani on Medium]]></description>
        <link>https://medium.com/@sapna.chatrani?source=rss-74c7211f59c7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*g8mY61jcgdZZebev</url>
            <title>Stories by Sapna Chatrani on Medium</title>
            <link>https://medium.com/@sapna.chatrani?source=rss-74c7211f59c7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 01:33:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sapna.chatrani/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Oracle -Advanced concepts]]></title>
            <link>https://medium.com/@sapna.chatrani/oracle-advanced-concepts-70f55d76a617?source=rss-74c7211f59c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/70f55d76a617</guid>
            <category><![CDATA[row-chaining]]></category>
            <category><![CDATA[oracle]]></category>
            <category><![CDATA[row-migration]]></category>
            <dc:creator><![CDATA[Sapna Chatrani]]></dc:creator>
            <pubDate>Sun, 31 Jul 2022 06:36:55 GMT</pubDate>
            <atom:updated>2022-07-31T06:38:27.511Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog I will try to explain some advance concepts which come handy in your daily tasks.</p><p>1- <strong>Row Chaining </strong>- What happens when we execute insert statement? Where the data is actually stored? To understand this we must first understand the different parameters used while creating the table.</p><p>When we create a table in oracle we specify certain storage parameters like Tablespace, PCT_FREE, PCT_INCREASE among others. But to understand the ROWCHAINING concept we will focus more on PCTFREE</p><pre>Create table explain_storage(<br>col1 int,<br>col2 varchar2(100)<br>.<br>.<br>.<br>coln date)<br>tablespace new_data_tbspc<br>storage(Initial 64k<br>Next 64k<br>PCTFREE 20<br>PCTINCREASE 50)</pre><pre>--<strong>Tablespace</strong> - A tablespace specifies the space allocated in the database for segments like table, index or temp. Each tablespace points to the physical location of datafile where the data is actually stored.<br>--<strong>Initial</strong> - specifies the size in bytes of the tables&#39;s first extent. The minimum value is the size of 2 data blocks.<br>--<strong>Next</strong> - specifies the size in bytes of the next extent to be allocated to the table<br><strong>PCTINCREASE</strong> - specifies the percent by which the third and subsequent extents grow over the preceding extent<br><strong>PCTINCREASE</strong> - specifies the percent of the block reserved for possible updates to rows that are already stored the in block. PCTFREE 20 means in each data block, 20% of space is reserved for future updates </pre><p>Coming back to <strong>Row Chaining</strong> - When we initially execute an insert statement, it stores the data in a data block under the tablespace specified for that table. Considering the row is stored in a single block, which has reserved 20% for future updates.</p><p>Now suppose we update this row which causes increase in the data length beyond the space available in the block and now it can’t be stored in single block. In such case another block is required to store the remaining data. Now the data for a single row is residing in 2 data blocks. This is called Row Chaining.</p><p>Row Chaining has an impact on the performance as you need to scan multiple block to read a single row. This can be avoided by specifying larger PCTFREE while creating the table which may have large set of columns with large field length.</p><p>2 - <strong>Row Migration</strong> - Row migration occurs when a row in table is updated but the space in the block is not enough to store the complete data row after update. In such case, the row is migrated to a complete new data block. The old block holds a pointer that refers to the new data block for that row.</p><p>Now if an index is defined in the table, that will still point to the old data block while reading that row, hence scanning 2 data blocks(old and new) to read single data row, which again causes performance issue.</p><p>I have shared this based on my experience hope this will be helpful.</p><p>Share your experience in comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70f55d76a617" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL & PL/SQL concepts]]></title>
            <link>https://medium.com/@sapna.chatrani/sql-pl-sql-concepts-8d441b1816cd?source=rss-74c7211f59c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d441b1816cd</guid>
            <category><![CDATA[plsql]]></category>
            <category><![CDATA[for-all]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[pragma]]></category>
            <category><![CDATA[bulk-collect]]></category>
            <dc:creator><![CDATA[Sapna Chatrani]]></dc:creator>
            <pubDate>Sat, 30 Jul 2022 09:58:08 GMT</pubDate>
            <atom:updated>2022-07-30T09:58:08.392Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog, I will demonstrate few sql/plsql concepts along with examples which could be helpful to prepare for interview.</p><p>1- Decode and case</p><p>Decode and Case both are alternatives for If Else logic.</p><pre>--DECODE<br>select DECODE(2,2,&#39;matched&#39;,&#39;not matched&#39;) from dual;<br>--output will be matched</pre><pre>select DECODE(2,1,&#39;matched&#39;,&#39;not matched&#39;) from dual;<br>--output will be not matched</pre><pre>Decode will compare first expression with second, if matches, it will result third expression else fourth.</pre><pre>--CASE<br>select case <br>when 2=2 then &#39;matched&#39;<br>else &#39;not matched&#39;<br>end out from dual;</pre><pre>--output matched<br></pre><p>2- Identify and delete duplicate records in table. In below example, we will see how to identify and delete duplicate records using rowid</p><pre>create table del_dup_rec<br>(name varchar2(100),<br>age int<br>);</pre><pre>insert into del_dup_rec values(&#39;Raj&#39;,20);<br>insert into del_dup_rec values(&#39;Alex&#39;,20);<br>insert into del_dup_rec values(&#39;Raj&#39;,20);<br>insert into del_dup_rec values(&#39;Alex&#39;,20);</pre><pre>select* from del_dup_rec;<br>Raj  20<br>Alex 20<br>Raj  20<br>Alex 20</pre><pre>--Query to find duplicate records:<br>SELECT *<br>  FROM del_dup_rec a<br> WHERE ROWID IN (SELECT MAX (ROWID)<br>                   FROM del_dup_rec b<br>                  WHERE a.name = b.name)</pre><pre>--output <br>Raj  20<br>Alex 20</pre><pre>--Query to delet duplicate records:<br>DELETE<br>  FROM del_dup_rec a<br> WHERE ROWID IN (SELECT MAX (ROWID)<br>                   FROM del_dup_rec b<br>                  WHERE a.name = b.name);</pre><pre>--2 rows will be deleted.</pre><p>3- WITH clause.</p><p>WITH clause is nothing but a sort of temporary table that is used to store the result of a query in memory which can then be called multiple times in main query.</p><p><strong>Usage </strong>-</p><p><strong>a</strong> - When we have a subquery that is being referred multiple times in the main query, then we can store the result of that query in with clause and then refer to with clause in main query instead of writing the subquery every time.</p><p><strong>b</strong> - When we need to refer few columns from a huge table with hundred of columns, then instead of referring the whole table in main query, we can select required fields from the table in with clause and use it in main query. This will help to reduce the memory consumption and improve the performance by avoiding to load the whole table while processing the query.</p><p>4 - How to access a table/view of one schema from another schema.</p><p>Suppose I have table <strong>tab1</strong> in schema <strong>schema1.</strong> I want to access tab1 from another schema <strong>schema2.</strong></p><p>This can be accomplished by following 2 steps</p><p>First you need to give select grants in tab1 in schema1 to schema2. Then you need to create synonym for tab1 in schema2.</p><pre>--login to schema1<br>grant select on tab1 to schema2.</pre><pre>--login to schema2<br>create or replace synonym tab1 for schema1.tab1;</pre><pre>now you should be able to query tab1 from schema2.</pre><p>5 - Bulk collect and FOR ALL</p><p>BULK COLLECT reduces context switches between SQL and PL/SQL engine and allows SQL engine to fetch the records at once. Now before understanding BULK collect, we must understand the concept of context switching.</p><p><strong>Context Switching</strong> - When you execute a PLSQL procedure or package that refers sql statements, then each time a SQL statement is encountered the PLSQL engine passes the SQL statement to SQL engine. SQL engine processes the statement and passes the result back to PLSQL engine. This process of passing the control b/w SQL and PLSQL engine is called context switching. The more the no of context switches the poor the performance.</p><p>To over come this performance issue, Bulk collect is used as it reduces the no of switches.</p><p>You can specify BULK COLLECT in your select statement. When this statement will be issued the control will be passed to SQL engine. SQL engine will select all the records and return the result set to PLSQL engine for further processing.</p><pre>Syntax for bulk collect<br>select col1,col2,….coln BULK COLLECT INTO bulk variable from table;</pre><p>FORALL</p><p>FORALL is used to perform bulk DML operations on data selected using bulk collect.</p><pre>Syntax for FORALL<br>forall x in 1..n<br>--write dml statement here.</pre><p>6 - Autonomous Transaction.</p><p>Autonomous transaction can be defined as a transaction within the transaction which can perform its operation and commit or rollback without having an impact on the outer transaction. Below example will illustrate the working of Pragma AUTONOMOUS_TRANSACTION.</p><pre>--<br>create table test_autonomous_txn<br>(name varchar2(100),<br> age int<br> );<br>insert into test_autonomous_txn values(&#39;Raj&#39;,20);<br>insert into test_autonomous_txn values(&#39;Alex&#39;,20);<br>select * from test_autonomous_txn;<br>--output<br>Raj 20<br>Alex 20</pre><pre>We have created a procedure with PRAGMA AUTONOMOUS_TRANSACTION where we are inserting a row in table and committing the transaction.</pre><pre>Now in a PLSQL block we are trying to delete a record from the table and then calling the above procedure and then rolling back the delete transaction. Here even though the commit is executed in autonomous block, the delete statement is not committed. </pre><pre>create or replace procedure autonomous_block<br>is<br>PRAGMA AUTONOMOUS_TRANSACTION;<br>begin <br>insert into test_autonomous_txn values(&#39;Brit&#39;,50);<br>commit;<br>end;<br>/</pre><pre>begin<br>delete from test_autonomous_txn where name=&#39;Alex&#39;;<br>autonomous_block; --commit inside this block.<br>rollback;<br>end;<br>/</pre><pre>--New record added but the one in delete statement didn&#39;t delete.</pre><pre>final records in the table: <br>Raj  20<br>Alex 20<br>Brit 50</pre><p>I hope these concepts along with examples will be helpful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d441b1816cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PostgreSQL — steps to migrate postgres from default directory to specific directory]]></title>
            <link>https://medium.com/@sapna.chatrani/postgresql-steps-to-migrate-postgres-from-default-directory-to-specific-directory-f4975c3e8388?source=rss-74c7211f59c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4975c3e8388</guid>
            <category><![CDATA[directory-migration]]></category>
            <category><![CDATA[posgresql]]></category>
            <dc:creator><![CDATA[Sapna Chatrani]]></dc:creator>
            <pubDate>Thu, 28 Jul 2022 17:17:38 GMT</pubDate>
            <atom:updated>2022-07-28T17:17:38.084Z</atom:updated>
            <content:encoded><![CDATA[<h3>PostgreSQL — steps to migrate postgres from default directory to specific directory</h3><p>Often when we install postgresql, it is installed in root directory i.e “var/lib/pgsql/data” and subsequently all the data files are created under this root directory. Since in most of the cases the root directory has very low space, it is quite obvious that over a short span of time we may face space issues and ultimately DB failure due to space issue.</p><p>To overcome this problem, we must shift the postgresql setup from this default directory to different mount point where we have ample space and also when need arises, more disk space can be added.</p><p>Considering that in your current setup the postgresql is in default directory, I will show some simple steps about how to migrate your existing setup to a new mount point.</p><p>1 -Stop the DB services using below command</p><pre>sudo service postgresql-9.6 stop</pre><p>2 -Create an empty directory in desired location say “/datadisk01/posgresqldata”</p><p>3 -Locate postgresql-9.6.service in /lib/systemd/system/</p><p>4 -Switch to root user (if not already) then go to location /etc/systemd/system</p><p>5 -Create file postgresql-9.6.service with below content.</p><pre>.include /lib/systemd/system/postgresql.service<br>[Service]<br>Environment=PGDATA=/datadisk01/postrgesqldata.9.6/data</pre><p>6 -Start the DB service</p><pre>sudo service postgresql-9.6 start</pre><p>Your database is now ready for use and all the data files will now be created under “/datadisk01/postrgesqldata.9.6/data”.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4975c3e8388" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PostreSQL — How to read data from JSON field]]></title>
            <link>https://medium.com/@sapna.chatrani/postresql-how-to-read-data-from-json-field-274020261e4d?source=rss-74c7211f59c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/274020261e4d</guid>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[json]]></category>
            <dc:creator><![CDATA[Sapna Chatrani]]></dc:creator>
            <pubDate>Wed, 27 Jul 2022 05:46:41 GMT</pubDate>
            <atom:updated>2022-07-27T05:46:41.326Z</atom:updated>
            <content:encoded><![CDATA[<h3>PostreSQL — How to read data from JSON field</h3><p>In this blog, I will try to explain (with Example) the steps to read data from a JSON field in PostgreSQL. JSON is a datatype that stores data in key-value pair. The advantage of JSON is the flexibility it provides to add as many number of fields in key-value format and also different number of/type of fields in each row.</p><p>As a first step, we create a simple table with field named info of type json.</p><pre>create table table_to_read_json_field</pre><pre>(id int,</pre><pre>info jsonb);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*EPVTaTyTh8V4VGvjNxCH1w.png" /></figure><p>Next we insert data into the table.</p><pre>insert into table_to_read_json_field values(1,&#39;{&quot;Name&quot;:&quot;Reader1&quot;,&quot;Age&quot;:29 ,&quot;Gender&quot;:&quot;Male&quot;}&#39;);</pre><pre>insert into table_to_read_json_field values(2,&#39;{&quot;Name&quot;:&quot;Reader2&quot;,&quot;Age&quot;:25 ,&quot;Gender&quot;:&quot;Female&quot;,&quot;Address&quot;:&quot;C1-202&quot;}&#39;);</pre><p>Note: in first statement, we inserted 3 fields in info column whereas in second statement, we inserted 4 fields.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*nTHEsml0EowvREcDrmM83Q.png" /></figure><p>Now we do a simple select from table to see how output looks.</p><pre>select * from table_to_read_json_field;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*Aip_GxjeNslrbmKQb4Qz2Q.png" /></figure><p>The output shows 1 row per id where all fields are in info column.</p><p>Now we want to read value for each key from json field as a separate column. This can be achieved by using postgres inbuild function <strong>jsonb_object_keys</strong> to extract each key and its value from json field.</p><pre>select id,<strong>jsonb_object_keys(info)</strong> key_col,<br><strong>info -&gt;&gt; jsonb_object_keys(info)</strong> val_col from table_to_read_json_field;</pre><p>Note: to extract the key use <strong>jsonb_object_keys(info) </strong>and to extract the value use <strong>info -&gt;&gt; jsonb_object_keys(info).</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*cg1Sznt-MP5jTSFiuXhr6w.png" /></figure><p>This is how we extracted key column and its value in separate fields in the final result.</p><p>Hope this simple example could be helpful for beginners.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=274020261e4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Steps to create JIRA Scrum board and Sprint]]></title>
            <link>https://medium.com/@sapna.chatrani/steps-to-create-jira-scrum-board-and-sprint-36e448713f4a?source=rss-74c7211f59c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/36e448713f4a</guid>
            <category><![CDATA[sprint-creation]]></category>
            <category><![CDATA[jira-scrum-board]]></category>
            <category><![CDATA[agile-methodology]]></category>
            <dc:creator><![CDATA[Sapna Chatrani]]></dc:creator>
            <pubDate>Tue, 26 Jul 2022 05:29:50 GMT</pubDate>
            <atom:updated>2022-07-27T11:08:18.263Z</atom:updated>
            <content:encoded><![CDATA[<p>This blog is about to show steps used to create JIRA scrum board &amp; Sprint from scratch with screenshots.</p><p>Login to JIRA so that you can view all projects for which you have access to create board. Click on boards tab to see the list of existing board and to create new board.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*PYlEDqB14-uE0wxXj5vOTA.png" /></figure><p>On the very right hand side click on <strong>create board.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*LIsJwlOeb49ygQdderJSjw.png" /></figure><p>It will prompt you for selecting type of board i.e Scrum or Kanban.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*zFGBrlgUIxfvfh7wav_wUw.png" /></figure><p>There are 3 options to select from to create a board as shown in screenshot.</p><p>first option allows you to create a new project and board.</p><p>second option allows you to create new board in existing project.</p><p>third option allows you to create board from pre-saved filters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*psp9A1srff-vidgOBXPO8A.png" /></figure><p>Here I have opted to create board from existing project i.e Sample Scrum Project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*PVreoXGWYXI2b8CaJOLPUA.png" /></figure><p>Once the board is created, it will take you to the backlog page. As I selected to create board from existing project so by default it will add stories which are in todo list under backlog section of this board.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*OAB_PmV-ogjtIStCAUvDiA.png" /></figure><p>Next step is to create sprint as backlog is ready.</p><p>The Sprint</p><p>Sprints are the heartbeat of Scrum, where ideas are turned into value.</p><p>click on <strong>create sprint</strong>. and it will create a new sprint</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*dHq1vJSYm6arxWgs1irFnw.png" /></figure><p>As you can see in below screenshot it has created the new sprint .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*_29YhZ525XyAAbqrgOpWOA.png" /></figure><p>Now your new sprint is ready and you can add stories, tasks to your new sprint. To add stories/tasks to new sprint simply drag the issues from backlog section to sprint section to add.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*-sqQqE_a0WWXx478fkSM-A.png" /></figure><p>Or you can create new stories/tasks/Epic by clicking on Create option in top menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Th587k1-B8vj33VrHpNPEQ.png" /></figure><p>Select the type of issue(Task/Bug/Story/Epic) you want to create and give the summary and other details like epic, label, sprint and click on create. It will create the issue under the selected sprint.</p><p>I hope these simple steps would be helpful for the beginners who wish to explore jira. Thank you</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36e448713f4a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Dictionary Views -Oracle v/s Azure SQL]]></title>
            <link>https://medium.com/@sapna.chatrani/data-dictionary-views-oracle-v-s-azure-sql-9c7c7b218019?source=rss-74c7211f59c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c7c7b218019</guid>
            <category><![CDATA[oracle]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[data-dictionary]]></category>
            <category><![CDATA[azure-sql-server]]></category>
            <dc:creator><![CDATA[Sapna Chatrani]]></dc:creator>
            <pubDate>Mon, 25 Jul 2022 05:34:33 GMT</pubDate>
            <atom:updated>2022-07-25T05:34:33.456Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog I am going to share some basic sql scripts to query data dictionary views in oracle and sql. These scripts will be helpful to those switching from oracle to azure or vice versa.</p><p>1- To get list of all tables/Views in a schema.</p><p>So there are 2 ways to get the list of objects in a schema.</p><pre>--Oracle<br>#Either login to the schema and run below query to get table/view list</pre><pre>select * from tab;</pre><pre>#Login as sys or admin and execute below query to get table/view list for particular schema</pre><pre>select owner,object_name,object_type from all_objects where owner=&#39;your schema name&#39;</pre><pre>--Azure<br>select * from information_schema.tables where table_schema=&#39;your schema name&#39;;<br>or<br>select * from sys.all_objects where schema_name(schema_id)=&#39;your schema name&#39;;</pre><p>2- To get the list of indexes defined on a table</p><pre>--Oracle</pre><pre>SELECT *<br>  FROM user_indexes<br>WHERE table_name = &#39;your table name&#39;;</pre><pre>--Azure</pre><pre>SELECT ao.name tablename,si.name indexname,si.type_desc<br> from sys.all_objects ao, sys.indexes si <br>  WHERE ao.object_id=si.object_id <br>  and ao.name=&#39;your table name&#39;;</pre><p>3- List all the Primary Keys defined in system</p><pre>--Oracle<br>SELECT constraint_name,CONSTRAINT_TYPE,TABLE_NAME<br> FROM all_constraints <br>WHERE constraint_type=&#39;P&#39;;</pre><pre>--Azure<br>SELECT schema_name(ao.schema_id) as schemaname,<br>       si.name as primarykey,<br>       si.is_primary_key,<br>       ao.name as table_name<br>FROM sys.all_objects as ao<br>    inner join sys.indexes as si<br>        on ao.object_id = si.object_id<br>        and si.is_primary_key = 1;</pre><p>4- List all dependent objects or list of objects in which table/view is referenced in. Below queries will give you the list of objects -Views, procedures etc in which a table/view is referenced</p><pre>--Oracle<br>SELECT owner,name,TYPE,referenced_name,referenced_type<br>  FROM all_dependencies<br>WHERE name = &#39;your table name&#39;;</pre><pre>--Azure<br>SELECT ed.referenced_schema_name,ed.referenced_entity_name,ao.name ,ao.type_desc<br> FROM sys.sql_expression_dependencies ed,sys.all_objects ao<br>WHERE ed.referencing_id=ao.object_id and <br>ed.referenced_entity_name=&#39;your table name&#39;;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c7c7b218019" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PostgreSQL Basics]]></title>
            <link>https://medium.com/@sapna.chatrani/postgresql-basics-f8ae72ae5a90?source=rss-74c7211f59c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/f8ae72ae5a90</guid>
            <category><![CDATA[postgresql-tablespace]]></category>
            <category><![CDATA[schema-creation]]></category>
            <category><![CDATA[postgresql]]></category>
            <dc:creator><![CDATA[Sapna Chatrani]]></dc:creator>
            <pubDate>Fri, 22 Jul 2022 04:53:47 GMT</pubDate>
            <atom:updated>2022-07-22T04:53:47.220Z</atom:updated>
            <content:encoded><![CDATA[<p>This Blog is about creating schema, roles, tablespace and tables in postgreSQL Database.</p><p>One the installation is complete, next step is to create tablespace. The tables are created in default tablespace. As a best practice, in order to achieve better performance and maintainability, we should define separate tablespaces for tables, indexes etc..</p><p>To see which all tablespaces are available in your DB, use below query. It will display the tablespaces along with directory location for each tablespace.</p><pre>select spcname, pg_tablespace_location(oid) from pg_tablespace;</pre><p>In below snippet, I will show how to create tablespace.</p><pre> create tablespace masterdata location  &#39;/datadisk01/db_tablespace/masterdata&#39;;</pre><pre> create tablespace index_master location &#39;/datadisk01/db_tablespace/index_master&#39;;</pre><p>Next step is to create user roles and schema. Before creating schema, role must be created. Below step will create schema named “dummy_user”</p><pre>-- Create role<br>create user dummy_user with<br>  login<br>  nosuperuser<br>  inherit<br>  nocreatedb<br>  nocreaterole<br>  noreplication<br>  valid until &#39;infinity&#39;<br>  password &#39;xxxxxxxxx&#39;;</pre><pre>--Create schema<br>create schema dummy_user authorization dummy_user;</pre><p>Once the schema is created, you can now create your tables under this schema. By default, the table will be created under default tablespace pg_default, even if we don’t specify tablespace clause. However, we can move this table to our defined tablespace using the alter command.</p><pre>CREATE TABLE dummy_user.First_Table<br>(<br>    col1 character varying(30) ,<br>    col2 timestamp without time zone,<br>    col3 double precision NOT NULL,<br>    col4 integer DEFAULT 0,<br>    col5 boolean DEFAULT false,<br>    CONSTRAINT col1pk PRIMARY KEY (col1,col4)<br>)<br>TABLESPACE pg_default;</pre><p>To see under which tablespace a table is created, use below query</p><pre>select * from pg_tables;</pre><p>To move a table from one tablespace to other, use below query</p><pre>--Move table to new tablespace.<br>alter table First_Table set tablespace masterdata;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f8ae72ae5a90" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PostgreSQL Installation on Unix/Linux platform]]></title>
            <link>https://medium.com/@sapna.chatrani/postgresql-installation-on-unix-linux-platform-eee88ae7cc36?source=rss-74c7211f59c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/eee88ae7cc36</guid>
            <dc:creator><![CDATA[Sapna Chatrani]]></dc:creator>
            <pubDate>Fri, 22 Jul 2022 04:18:59 GMT</pubDate>
            <atom:updated>2022-07-22T04:18:59.782Z</atom:updated>
            <content:encoded><![CDATA[<p>This blog is about PostgreSQL installation on Linux platform.</p><p>Before starting the installation we need to download the RPM file based on what version of PostgreSQL we want to install and on what platform we want to setup the installation. From the below link, you get to choose the platform, version and architecture you need to install.</p><p>Based on your selection, you will get the RPM(RedHat Package Manager) download link.</p><p><a href="https://www.postgresql.org/download/linux/redhat/">Linux downloads (Red Hat family)</a></p><p>Next - copy the download link and go to your linux/unix box and follow the given steps-</p><pre>--To download and install RPM<br>sudo yum install -y <a href="https://download.postgresql.org/pub/repos/yum/reporpms/EL-6-i386/pgdg-redhat-repo-latest.noarch.rpm">https://download.postgresql.org/pub/repos/yum/reporpms/EL-6-i386/pgdg-redhat-repo-latest.noarch.rpm</a></pre><pre>-- List various components<br>   sudo yum list postgresql*</pre><pre>-- Install postgresql from RPM<br>   sudo yum install postgresql96-server</pre><p>Once PostgreSQL is installed on your machine, next step is to initialize the DB</p><pre>--initialize  the new db<br>sudo /usr/pgsql-9.6/bin/postgresql96-setup initdb</pre><p>After initialization, start the DB services.</p><pre>--start the service<br>  sudo service postgresql-9.6 start<br>       or <br>  sudo /usr/pgsql-9.6/bin/pg_ctl start</pre><p>To start/stop or check your DB status, use below commands</p><pre>--To check DB status<br>   sudo service postgresql-9.6 status <br>       or <br>   sudo /usr/pgsql-9.6/bin/pg_ctl status</pre><pre>--To Stop DB services<br>   sudo service postgresql-9.6 stop <br>       or <br>   sudo /usr/pgsql-9.6/bin/pg_ctl stop</pre><pre>--To start DB services<br>   sudo service postgresql-9.6 start<br>       or <br>   sudo /usr/pgsql-9.6/bin/pg_ctl start</pre><p>Your DB is now ready for use. In my next blog, I will explain how to create schema and tables in postgresql DB.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eee88ae7cc36" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Oracle VS Azure SQL (Date Functions)]]></title>
            <link>https://medium.com/@sapna.chatrani/oracle-vs-azure-sql-date-functions-c2203c6bb811?source=rss-74c7211f59c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2203c6bb811</guid>
            <category><![CDATA[date-function]]></category>
            <category><![CDATA[sql-azure]]></category>
            <category><![CDATA[oracle]]></category>
            <dc:creator><![CDATA[Sapna Chatrani]]></dc:creator>
            <pubDate>Thu, 21 Jul 2022 04:36:07 GMT</pubDate>
            <atom:updated>2022-07-21T04:36:07.353Z</atom:updated>
            <content:encoded><![CDATA[<p>In this Blog I will be explaining how to use date functions Oracle and AzureSQL</p><p>1- How to get system date.</p><pre> --<strong>Oracle</strong><br>    select sysdate from dual;<br>                <br> --<strong>Azure</strong><br>    select getdate();</pre><p>2- Date vs datetime<br> Alternate for date() in azure is datetime()<br> Syntax to convert date in specific format</p><pre> --<strong>oracle</strong><br>   select to_date(sysdate,&#39;dd/mm/yyyy&#39;) from dual;<br>   output- 19/07/2022<br> --<strong>Azure</strong> <br>   select convert(date,getdate(),11);<br>   output- 19-07-2022</pre><p>3- Extract day from date.</p><p>Both queries will return integer value for current day(if its 19th of the month it will return 19)</p><pre>--<strong>Oracle</strong><br>   select extract(day from sysdate) from dual;<br>--<strong>Azure</strong> <br>   select day(getdate());</pre><p>4- Extract month from date<br> Both queries will return integer value for current month(if its july month it will return 7)</p><pre>--<strong>Oracle</strong><br>   select extract(month from sysdate) from dual;<br>--<strong>Azure</strong> <br>   select month(getdate());</pre><p>5- Extract year from date<br> Both queries will return integer value for current year</p><pre>--<strong>Oracle</strong><br>   select extract(year from sysdate) from dual;<br>--<strong>Azure</strong> <br>   select year(getdate());</pre><p>6- First day and last day of current month. Sometimes its quite tricky to extract values for 1st or last day of current or previous months.</p><pre>--<strong>Oracle</strong><br>    SELECT TRUNC(SYSDATE,&#39;MM&#39;)AS FIRST_DAY, LAST_DAY TRUNC(SYSDATE)) AS LAST_DAY<br>      FROM DUAL;<br>    output - 01/07/2022 and 31/07/2022<br> <br>--<strong>Azure<br></strong>   --<strong><em>First Day</em></strong><br>   select dateadd(dd,-day(getdate()-1),getdate()) FIRST_DAY;<br>    output - 01/07/2022<br>   <br>   --Current date is 19th. day(getdate()-1) will return 18. dateadd function will add days(-18 days to current date) giving 1st of the month(it will add -18 to 19)<br>   <br>  --<strong><em>Last Day</em></strong><br>   select dateadd(dd,-(day(getdate())),dateadd(mm,1,getdate()))  LAST_DAY;<br>   output - 31/07/2022<br>   <br>   --Current date is 19th. day(getdate()) will return 19.dateadd(mm,1,getdate())will return 19-08-2022. dateadd function will add days(-19 days to 19th of next month) giving last of the month</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2203c6bb811" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Oracle VS Azure SQL (String Functions)]]></title>
            <link>https://medium.com/@sapna.chatrani/oracle-vs-azure-sql-34a745087d25?source=rss-74c7211f59c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/34a745087d25</guid>
            <category><![CDATA[sql-azure]]></category>
            <category><![CDATA[inbuild-functions]]></category>
            <category><![CDATA[string-functions]]></category>
            <category><![CDATA[oracle]]></category>
            <dc:creator><![CDATA[Sapna Chatrani]]></dc:creator>
            <pubDate>Thu, 21 Jul 2022 03:51:29 GMT</pubDate>
            <atom:updated>2022-07-21T04:43:08.857Z</atom:updated>
            <content:encoded><![CDATA[<p>In this Blog I will explaining Azure sql functions for corresponding Oracle inbuilt functions.</p><p>1- NVL() vs COALESCE() and ISNULL()</p><p>In oracle we use NVL to assign a default value to null value in a field where as in Azure we can use either COALESCE or ISNULL.</p><pre>— Oracle</pre><pre>select NVL(emp_address,’Not Available’) from employee;</pre><pre>— Azure SQL</pre><pre>select COALESCE(emp_address,’Not Available’) from employee;</pre><pre>select ISNULL(emp_address,’Not Available’) from employee;</pre><p>2-INSTR() -&gt; CHARINDX()</p><p>In oracle instr() function is used to return the position of a character from the given string.<br>In Azure inbuilt function charindex() is used to return the position of a character from the given string.</p><pre>- <strong>Oracle</strong><br>select INSTR(&#39;John Wilson&#39;, &#39;o&#39;) from dual;</pre><pre>- this will return 2(first position of &#39;o&#39; in string).</pre><pre>select INSTR(&#39;John Wilson&#39;, &#39;o&#39;,3) from dual;</pre><pre>- this will return 10(position of first o starting from index 3)</pre><pre>- <strong>Azure</strong><br>select CHARINDEX(&#39;o&#39;,&#39;John Wilson&#39;,1);</pre><pre>- this will return 2(first position of o starting from index 1)</pre><pre>select CHARINDEX(&#39;o&#39;,&#39;John Wilson&#39;,3);</pre><pre>- this will return 10(position of first o starting from index 3)</pre><p>3- SUBSTR() -&gt; SUBSTRING()<br>Although the inbuilt function name is different, the syntax is same.<br>To return a substring from a given text<br>In oracle inbuild function substr()<br>In azure sql inbuild function SUBSTRING()</p><pre>- <strong>Oracle</strong><br>select SUBSTR(&#39;John Wilson&#39;, 6,3) from dual;</pre><pre>- this will return &#39;Wil&#39;</pre><pre>- <strong>Azure</strong><br>select SUBSTRING(&#39;John Wilson&#39;, 6,3) from dual;</pre><pre>- this will also return &#39;Wil&#39;</pre><p>4- LISTAGG() -&gt; STRING_AGGREGATE()<br>To convert rows to delimited column,<br>In oracle we use LISTAGG() function.<br>In azure we use STRING_AGGREGATE()function.</p><pre>-common code<br>create table listagg_test(deptid int,empname varchar2(50));<br>insert into listagg_test values(1,&#39;Jon&#39;);<br>insert into listagg_test values(1,&#39;Jacob&#39;);<br>insert into listagg_test values(1,&#39;Jiemer&#39;); insert into listagg_test values(2,&#39;Ron&#39;);<br>insert into listagg_test values(2,&#39;Raj&#39;);<br>commit;</pre><pre>- <strong>oracle</strong><br>SELECT deptid, LISTAGG (empname, &#39;;&#39;) WITHIN GROUP (ORDER BY empname) FROM listagg_test group by deptid</pre><pre>- <strong>Azure</strong><br>select deptid, STRING_AGG(empname,&#39;;&#39;) WITHIN GROUP (ORDER BY empname) from listagg_test group by deptid;</pre><pre>--In both cases output will be 1 Jacob;Jiemer;Jon 2 Raj;Ron</pre><p>Please share your views/comments if this post was helpful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34a745087d25" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>