Yash Sanghvi has Published 220 Articles

Auto-format code in Arduino IDE

Yash Sanghvi

Yash Sanghvi

Updated on 23-Mar-2021 11:01:59

3K+ Views

Formatting the code is quite important to make it readable. It is recommended that you properly format the code regularly, and especially before sharing it with someone else.Follow these steps to auto-format code in Arduino IDE −Go to ToolsClick on Auto FormatAlternatively, you can press Ctrl+T on your keyboard. This ... Read More

How to change the baud rate of the Serial Monitor in Arduino?

Yash Sanghvi

Yash Sanghvi

Updated on 23-Mar-2021 10:54:01

6K+ Views

In order to change the baud rate of the Serial Monitor, go to Tools -> Serial Monitor (or press Ctrl+Shift+M alternatively).Make sure you have a board connected to your PC/Laptop, or the Serial Monitor won't open. Also, make sure that the Port corresponds to the connected board.Once the Serial Monitor ... Read More

What all constraints can be added to a PostgreSQL table?

Yash Sanghvi

Yash Sanghvi

Updated on 02-Feb-2021 13:13:19

160 Views

There are 6 types of constraints that can be generally used with a PostgreSQL table. They are listed and explained below −NOT NULL CONSTRAINTThis is a very common constraint. If there is a particular column that cannot have null values, you add this constraint at the time of table creation. ... Read More

Create Primary Key on an existing table in PostgreSQL?

Yash Sanghvi

Yash Sanghvi

Updated on 02-Feb-2021 13:09:44

2K+ Views

Although quite infrequent, you may come across situations wherein you need to define the primary key on an existing table. This can be achieved using the ALTER TABLE statement.The syntax is −ALTER TABLE table_name ADD PRIMARY KEY (column_name1, column_name2, …., columns_nameN)As can be seen from the above syntax, you can ... Read More

Extract day, hour, minute, etc. from a datetime column in PostgreSQL?

Yash Sanghvi

Yash Sanghvi

Updated on 02-Feb-2021 13:08:17

945 Views

Let us create a new table containing a single timestamp column −CREATE TABLE timestamp_test(    ts timestamp );Now let us populate it with some data −INSERT INTO timestamp_test(ts) VALUES(current_timestamp), (current_timestamp+interval '5 days'), (current_timestamp-interval '18 hours'), (current_timestamp+interval '1 year'), (current_timestamp+interval '3 minutes'), (current_timestamp-interval '6 years');If you query the table (SELECT * ... Read More

Aliasing in PostgreSQL?

Yash Sanghvi

Yash Sanghvi

Updated on 02-Feb-2021 13:05:41

157 Views

Often, we have some very long table names, and writing the table name every time is troublesome. We can use aliasing to help us there, thanks to which, we will need to write the long table name only once.The table aliases are generally written in the FROM part of the ... Read More

How to combine different columns of a table to yield a single column in query output in PostgreSQL?

Yash Sanghvi

Yash Sanghvi

Updated on 02-Feb-2021 13:02:48

1K+ Views

Suppose you have a table user_info that contains the state and district of different users. An example is given below −namedistrictstateAnilMumbaiMaharashtraJoyJhalawarRajasthanRonPuneMaharashtraReenaMeerutUttar PradeshNow, if you want to combine the state and district in a single field called location, this is how you should be able to do it −SELECT name, district ... Read More

How to look for partial string matches in queries in PostgreSQL?

Yash Sanghvi

Yash Sanghvi

Updated on 02-Feb-2021 13:00:52

4K+ Views

Suppose you have a table user_info containing the names of users and their addresses. An example is given below −nameaddressAnilAndheri, Mumbai, MaharashtraJoyChandni Chowk, DelhiRonBandra, Mumbai, MaharashtraReenaOld Airport Road, Bengaluru, KarnatakaNow, if you want to just extract the information of users who stay in Mumbai, you can do that using the ... Read More

How to apply DISTINCT constraint on select columns in queries in PostgreSQL?

Yash Sanghvi

Yash Sanghvi

Updated on 02-Feb-2021 12:57:26

114 Views

Suppose you have a table exam_scores containing 5 columns. An example is given below with some dummy data.nameroll_nosubjecttotal_marksmarks_obtainedAnil1English10056Anil1Math10065Anil1Science10045Roy2English10078Roy2Math10098Roy2Science10067Now, one student could have sat for exams of multiple subjects, and therefore, there are multiple rows for 1 student. If you wish to find out the total number of students in the ... Read More

CASE WHEN in PostgreSQL?

Yash Sanghvi

Yash Sanghvi

Updated on 02-Feb-2021 12:55:49

2K+ Views

If you are a programmer, you may be very familiar with IF-ELSE statements. The equivalent in PostgreSQL is CASE WHEN.Let’s understand with an example. If you have table marks containing percentage marks of a student, and you want to find out whether the students have passed or failed. An example ... Read More

Advertisements