PostgreSQL Archives - Ian Carnaghan

How to increase the length of a character varying datatype in Postgres without data loss

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...

Sep 2 · 9 sec read >

How to copy data from one table to another using pgsql

If you need to copy data from one table (table_a) into another table (table_b) using pgsql. There are 2...

Apr 7 · 19 sec read >

How to copy a columns data from one table into a column in another table using PostGreSQL

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...

Apr 7 · 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...

Apr 7 · 5 sec read >

How to create a backup of a PostgreSQL database to a SQL file

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...

Apr 7 · 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...

Apr 7 · 7 sec read >

How to import a CSV file into a PostgreSQL database table

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...

Apr 7 · 13 sec read >

How to export data to a CSV file from a PostgreSQL database together with table headings

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...

Apr 7 · 19 sec read >

How to export data to a CSV file from a PostgreSQL database

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...

Apr 7 · 13 sec read >