PostgreSQL

How to increase the length of a character varying…

Run the following command: alter table TABLE_NAME alter column COLUMN_NAME type character varying(120); This will extend the character varying column field size to 120. Remember to change TABLE_NAME to the relevant table...
Ian Carnaghan
9 sec read

How to copy data from one table to another…

If you need to copy data from one table (table_a) into another table (table_b) using pgsql. There are 2 methods on how to do...
Ian Carnaghan
19 sec read

How to copy a columns data from one table…

How to copy a columns data from one table into a column in another table using PostgreSQL? Eg. name columns data from the users table into namecolumn in the new_users table. Execute the query below with different column names and table names and all the data for a specific column will be...
Ian Carnaghan
15 sec read

How to check what version of PostgreSQL your running

Run the following query: SELECT version(); The result will look as below:                                                version ————————————————————————————————— PostgreSQL 8.3.7 on i486-pc-linux-gnu, compiled by GCC gcc-4.3.real (Ubuntu 4.3.3-5ubuntu4)...
Ian Carnaghan
5 sec read

How to create a backup of a PostgreSQL database…

How to create a backup of a PostgreSQL database to a sql file? This sql file then can be used to restore the database on a later stage. Follow the steps below in order to create a...
Ian Carnaghan
45 sec read

Eliminating duplicate rows from result-set using PostgreSQL

Use the DISTINCT ON keyword in your query To do a case-insensitive search do the following query SELECT DISTINCT ON(upper(surname)) surname FROM employees ORDER BY upper(surname) This will return non-duplicate surnames.  
Ian Carnaghan
7 sec read

How to import a CSV file into a PostgreSQL…

Type in the following command in postgres using the command line: copy products from ‘/home/user/products.csv’ using delimiters ‘,’ products = (Database Table) ‘/home/user/products.csv‘ = (Location of the csv file) You need...
Ian Carnaghan
13 sec read

How to export data to a CSV file from…

Type in the following command in postgres using the command line: copy products to ‘/home/user/products.csv’ delimiters ‘,’ CSV HEADER products = (Database Table) ‘/home/user/products.csv‘ = (Location where to save the csv...
Ian Carnaghan
19 sec read

How to export data to a CSV file from…

Type in the following command in postgres using the command line: copy products to ‘/home/user/products.csv’ delimiters ‘,’ products = (Database Table) ‘/home/user/products.csv‘ = (Location where to save the csv file) You...
Ian Carnaghan
13 sec read