PostgreSQL : Inserting data into a table using Select query.

This is a small post describing the PostgreSQL query for inserting data into a table using Select Query, as I had to use it for solving some issue in one of my projects. So, the query is below :

INSERT INTO films (code, title, did, date_prod, kind)
    VALUES ('T_601', (SELECT title from FilmCode where id = 'T_601') , 
106, '1961-06-16', 'Drama');

So, what you have to basically do is to put the ‘Select’ query in round brackets () and execute the query [ The brackets are the main thing to watch out for, as, otherwise the query will give an error on execution.]. The required value will be fetched from the source table and inserted into the desired table.

Hope this helps šŸ™‚

Could not connect to the Server : Connection timed out


If you trying to connect to a database, directory server or for any server for that matter and while you are running your application server, you Ā are getting the Error message Connection timed out in the stack trace, then, try the following remedies and see if these can help you :

1. Check in your configuration file whether you have given the correct IP address and port number of the server your trying to connect to.

2. Check if the credentials i.e. usernames and passwords are correct or not.

3. Unblock the ports of the server which you want to access in the firewall of the server.

Try running the application server once again and see if Ā this helps or not.

Thanks šŸ™‚

/usr/bin/gem:23:uninitialized constant Gem::GemRunner(NameError)

I came across this error when I tried to update my RubyGems because my Rails wanted version 1.3.1 and I was having 1.2.0.

When I wroteĀ  “sudo gem update –system” on the terminal I came across the following error :

/usr/bin/gem:23: uninitialized constant Gem::GemRunner(NameError)

So the solution is to add require ‘rubygems/gem_runner’ line toĀ  /usr/bin/gem . If you don’t know how to do this or if you are a newbie, don’tĀ  worry, I am explaining it below .

Step 1 : Go to the terminal and type the following

$ cd /usr/bin/

This will move you to the folderĀ  /usr/bin/

Step 2 : Type the following command to open up file in text editor

$ sudo pico gemĀ Ā Ā  and enter your password

Step 3 : Add the line ‘rubygems/gem_runner’ to the gem file that opens up after Step 2 ,

Add the line beforeĀ  require ‘rubygems’
Step 4 : Press Ctrl+X to save the file and exit

4a) Press ‘Y’ if you think you have done the relevant changes correctly and want to save the file. Otherwise,

Press ‘N’ and move out without saving.

4b) If you press ‘Y’ in the previous step, it will ask you if you want to save the file with same name? , Just

press ‘Enter’ and move out.

I hope this solution will help you to solve your problem. I was successful in solving my problem on my Ubuntu 8.04.