vimalkumar.in

/blog

PostgreSQL Notes

Some things I’ve learnt recently.

Simple boolean function to check if a column exists

1
SELECT EXISTS(SELECT 1 FROM information_schema.columns WHERE table_name = tabname AND column_name = col1)

Identify duplicate values in columns

1
SELECT key FROM tabname GROUP BY key HAVING (COUNT(key) > 1)

col1 is an integer but I wanted it formatted as text in my python script

1
SELECT CAST(col1 AS TEXT) FROM tabname