There is a simpler way
Basically 3 points to consider when planning to user PostGreSQL from cmd prompt.
- Semi-colon
- Set Search path
- Handle case sensitivity and naming conventions
First answer is to add a semi-colon after the statement.
Second, if you are using postgre from command line , and you have created you tables in public schema, so every time instead of writing
SELECT * FROM public."Users";
we can set the search path Set Search Path Temporarily in That Particular Session:
psql -U your_username -d your_database
SET search_path TO public;
SELECT * FROM Users;
Permanently Setting the Search Path for a Role:
psql -U your_username -d your_database
ALTER ROLE your_username SET search_path TO public;
SELECT * FROM Users;
Lastly, very important case-sensitivity. If you create tables using PgAdmin then they will be created as "Users" so if you will run statement from command prompt as
SELECT * FROM Users;
OR
SELECT * FROM users;
that wont work, you will have to write
SELECT * FROM "Users";
So its better to create table in lowercase and alter existing tables as
ALTER TABLE "Users" RENAME TO users;
Hope this helps
select * from <table> limit 1;- withlimit 1and with semicolon?SELECT pg_size_pretty(pg_relation_size('<table>'));Also, any concurrent activity? There may be locks ... Look at:SELECT * FROM pg_stat_activity;andSELECT * FROM pg_locks;;to end the statement?