<?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 Fikri Rahmat Nurhidayat on Medium]]></title>
        <description><![CDATA[Stories by Fikri Rahmat Nurhidayat on Medium]]></description>
        <link>https://medium.com/@fikrirahmatnurhidayat?source=rss-48ec321f0bf0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*D0wcc85eSulLdr1dnT-P4g.png</url>
            <title>Stories by Fikri Rahmat Nurhidayat on Medium</title>
            <link>https://medium.com/@fikrirahmatnurhidayat?source=rss-48ec321f0bf0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 09:33:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fikrirahmatnurhidayat/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[Yes, you can do copy and paste in your Postgresql query]]></title>
            <link>https://medium.com/@fikrirahmatnurhidayat/yes-you-can-do-copy-and-paste-in-your-postgresql-query-63ed8d247069?source=rss-48ec321f0bf0------2</link>
            <guid isPermaLink="false">https://medium.com/p/63ed8d247069</guid>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[postgresql]]></category>
            <dc:creator><![CDATA[Fikri Rahmat Nurhidayat]]></dc:creator>
            <pubDate>Fri, 12 Apr 2019 15:30:22 GMT</pubDate>
            <atom:updated>2019-04-12T15:44:57.176Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bZZLpdpMiwhyzRqKAc7OyQ.jpeg" /></figure><p>Have you ever been getting annoyed when you try to do some query and copy the result? Like, uh, when your coworker asks you about some data that is stored in database, in my case it was the plugin_content-manager_schema in <em>Strapi</em> which is requiring an update on that specific key after you create new table with bookshelf template because <em>Strapi</em> doesn’t update that schema automatically. It is quite an effort to do that thing, right? You need open up <em>pgAdmin </em>(CLI can’t show that schema because it’s too long), start the server and then do some query, see the result then copy that and finally put it on some file, for example <em>schema.txt.</em> Annoying right?</p><h4>So, I’m here to help you <em>(or might not help you)</em> to get rid of that thing, by only using three lines of bash command.</h4><h3>Requirement</h3><p>Here’s the requirement that you should install to your machine :</p><ol><li><strong>xclip</strong> <em>(Yes, this tutorial only covers linux user, because I don’t know what exactly macOS is)</em></li><li><a href="https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-16-04"><strong>postgresql</strong></a></li></ol><h3>Installing xclip (Ubuntu 18.04)</h3><p>I’m not going to waste my brain here to write a chain of beautiful words or phares, let’s get straight to it.</p><p>Open up your terminal, and make sure you have internet connection.</p><p>Run this command</p><pre>$ sudo apt-get update<br>$ sudo apt-get install xclip</pre><p>Then you should be able to run this :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*AzZjj7E6WoLZk2x8sJOnRw.png" /><figcaption>Output of xclip -h</figcaption></figure><p>For another linux distribution, you can search it by yourself, it’s not quite hard. But, to be honest I don’t know how to install xclip on another distribution because I never use one of them except ubuntu, haha.</p><h3>Copying Entry Value From PSQL Query Result</h3><p>Like I said before, We might want to copy the result of psql query, some of them are really long value which terminal can’t show that value.</p><p>Let me give you an example of what’s going on when you try query a long data value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CfVbJ4iL7oBbLnoegs625g.png" /></figure><p>See? Terminal can’t show that long value, so what we need to do is copying that result into clipboard then place it on a file called <em>schema.txt</em></p><p>Run this command to query and copy that query result :</p><pre>psql -A &lt;YOURDBNAME&gt; -c “SELECT * FROM <strong><em>table_name </em></strong>WHERE <strong><em>column_name</em></strong>=’some_value’;” --tuples-only | xclip</pre><h4>What does that line mean?</h4><ul><li><strong><em>psql </em></strong>let you run postgresql-client inside your machine.</li><li><strong><em>-A </em></strong>to<strong><em> </em></strong>get rid of align information so you can copy that value without copying the other thing of the result.</li><li><strong><em>-c </em></strong>can<strong><em> </em></strong>help you to run SQL command inside double-qoutes.</li><li><strong><em>--tuples-only </em></strong>to only leave column value as result on that command.</li><li><strong><em>| xclip </em></strong>to copy the result of the entire command.</li></ul><p>So, we’ve already copy the query result, all we need to do is store that result into <em>schema.txt</em></p><pre>* <em>Store clipboard to schema.txt</em></pre><pre>xclip -o &gt; schema.txt</pre><pre><em>* To check if that value has already stored on schema.txt</em></pre><pre>nano schema.txt</pre><h4>Congratulation, now you can copy query result and store it to whatever file you want by two commands. Easy right?</h4><h3>Use your clipboard to insert some value on database</h3><p>Cool, we’re now able to copy a query result, now let’s say we want to put it to some table inside your database. Here’s what you need to do :</p><p>Let’s say, I want to put that value on table called <strong><em>table_name2</em></strong><em> </em>in column<em> </em><strong><em>column_name</em></strong><em> </em>at<em> schema.</em></p><p>Run this command on your terminal :</p><pre>xclip schema.txt<br>psql <strong><em>dbname </em></strong>-c &quot;INSERT INTO <strong><em>table_name2 (column_name</em></strong>) VALUES (&#39;`xclip -o`&#39;);&quot;</pre><p>We need this <strong>`` </strong>character to escape psql command, so you will be able to do some bash command inside psql command.</p><p>Looks like that’s it, I hope you enjoy, or if you don’t, don’t hesitate to give me some negative comment. Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63ed8d247069" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>