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 statement, or the JOIN part.For example, consider that we have two tables, marks, and student_info, defined respectively below −marksnameroll_noperc_marksAniket1224Siddhi4565Yash2642Isha5687student_infonameroll_noagegenderAniket1226MIsha5625FSiddhi4523FYash2625MNow, if you want to see the name, roll_no, perc_marks, and age of the student in one query, your query will look like this −SELECT marks.name, marks.roll_no, marks.perc_marks, student_info.age FROM marks LEFT ... Read More
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 || ', ' || state as location from user_infoThe || operator is the string concatenation operator. The output will be −namelocationAnilMumbai, MaharashtraJoyJhalawar, RajasthanRonPune, MaharashtraReenaMeerut, Uttar PradeshSimilar operations can also be performed on numerical values. Suppose you have a table marks containing the total marks scored by students and the maximum ... Read More
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 LIKE command and the % operator.SELECT * from user_info where address LIKE '%Mumbai%'The output will benameaddressAnilAndheri, Mumbai, MaharashtraRonBandra, Mumbai, MaharashtraNotice that we have added % operator on both sides of Mumbai. This means that anything can precede Mumbai and anything can be after Mumbai. We just want the string to ... Read More
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 class, you may want to find the number of distinct values of roll_no. You can apply the distinct constraint on a specific column as follows −SELECT DISTINCT ON (roll_no) name, roll_no FROM exam_scores ORDER BY roll_no DESCHere’s what the output of the above query will look like −nameroll_noRoy2Anil1You can also ... Read More
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 table is given below.nameperc_marksAnil24Joy65Ron42Reena87Say the passing marks are 40. Now, if the student has scored above 40 marks, we want to print ‘PASS’ against that student’s name, otherwise ‘FAIL’. This is how you can do it −SELECT name, CASE WHEN perc_marks >= 40 THEN 'PASS' ELSE 'FAIL' END status from ... Read More
Quite often, you need the current timestamp in PostgreSQL. You do that as follows −SELECT current_timestampIt will output the current time. The output will look like the following −2021-01-30 15:52:14.738867+00Now, what if you want the relative time instead of the current time? For example, if you want the time corresponding to 5 hours prior to the current time, you can get it using intervals.SELECT current_timestamp - interval '5 hours'The output will be different every time. At the time of writing this, the output was −2021-01-30 10:57:13.28955+00 You can also do these operations on date instead of timestampsSELECT current_dateOutput2021-01-30SELECT current_date + ... Read More
We can use Selenium with Ruby. First of all we have to install Ruby in the system. For installation in Windows, we have to take the help of the RubyInstaller package by navigating to the link −https://rubyinstaller.org/Click on Download.The various versions of Ruby Installers links get displayed. Select the latest version and click on it.Click on the Save File button to download the corresponding rubyinstaller.exe file.Once the download is completed, accept the license agreement and proceed to the next steps till installation is completed.To have Selenium webdriver package for Ruby, run the command −gem install selenium−webdriverTo have Rest−Client package for ... Read More
We can stop the page loading in Firefox programmatically. This can be done by first setting page load time with the help of the pageLoadTimeout method.The time to wait for the page load is passed as a parameter to that method.Syntaxdriver.manage().timeouts().pageLoadTimeout(10, TimeUnit.MILLISECONDS);The page is forced to stop from loading with the help of the Javascript Executor. Selenium executes JavaScript command (window.stop() to stop page load) with the help of the executeScript method.Syntax((JavascriptExecutor)driver).executeScript("window.stop();");Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class StopPageLdWait{ public static void main(String[] args) { System.setProperty("webdriver.gecko.driver", "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe"); ... Read More
Selenium RC is a key part in Selenium. It is a framework for testing that allows testers and developers to design test scripts in multiple languages to automate frontend UI test cases. It has a client library and a server that starts and quits the browser sessions by defaultServer injects Selenium core (a program in JavaScript) to the browser. The Selenium Core gets the commands from the RC server. Selenium Core executes the commands in JavaScript. Then the JavaScript commands provide instructions to the browser. Finally, the browser runs the instructions given by the Selenium Core and sends a complete ... Read More
Indexing is used to speed up query execution in PostgreSQL, and any relational database in general. PostgreSQL tables primarily support several index types. Let us discuss 3 frequently user index types in brief −HashThese indexes can only handle equality comparisons. In other words, if I want to check if itemA = itemB, then hash indexes are useful. It is not suited for other types of operations, like >, =, 40then this index will be useless, and PostgreSQL will organize the query plan assuming the index doesn’t exist.B-treeThis is the default index used by PostgreSQL. In other words, if you ... Read More