Below is the syntax to change the data type of a column. tablename is the name of the table, columnname
Continue readingCategory: Postgresql
PostgreSQL – Count distinct over multiple columns
Sql statement to get the count of distinct values in a column: SELECT COUNT (DISTINCT col1) FROM table1; Below is
Continue readingPostgreSQL – Renaming a Column
Below is the syntax to rename a column in Postgres where tablename is the name of the table and columnname
Continue readingPostgreSQL – Change Table Owner
Below is the syntax to change the owner of a table in Postgres database: Alter table schemaname.tablename owner to new_owner;
Continue readingPostgreSQL – Drop User
Below is the syntax to delete a database user in postgres. DROP USER rolename; DROP ROLE rolename; Both the above
Continue readingPostgresql – How to get current day, month, year from date
Run the below command to get current day, month and year from date in postgres database. Sql query to view
Continue readingPostgreSQL – Get current value and next value of a Sequence
Postgres provides currval and nextval functions for sequence manipulation. currval function returns the current value of the sequence without advancing
Continue readingPostgreSQL – Drop Column
Syntax to drop a column in postgres database: ALTER TABLE tablename DROP COLUMN columnname;
Continue readingPostgreSQL – Get current user
Run the below select statement to obtain the username of the current session in Postgres database. select current_user;
Continue readingPostgreSQL – Get current database name
Run the below command to check the current database you are connected to in Postgres. SELECT current_database();
Continue reading