Martin Ambrose
Martin Ambrose

Reputation: 3

Renaming tables

I keep getting a syntax error in PSQL and I can't figure out why. Any help would be greatly appreciated

SELECT page_code, developer
FROM page
WHERE data_approved=null and approved_by=null
ALTER TABLE page 
RENAME COLUM page_code TO unapproved;

Upvotes: 0

Views: 111

Answers (2)

Subhash Kumar
Subhash Kumar

Reputation: 1

ALTER TABLE table_name RENAME new_table_name;

this command will help you to change table name Rename is used to change the table name and change is used to rename column name

Upvotes: 0

Dmitrii Bychenko
Dmitrii Bychenko

Reputation: 186668

You are, probably, looking for alias, not for altering table:

 SELECT page_code AS unapproved, 
        developer
   FROM page
  WHERE data_approved IS null 
    AND approved_by IS null 

Note, that page table will stay intact while its page_code field will be represented in this particular query as unapproved. Please, be very careful with altering tables since doing this you change the rules for all the users.

Another issue is = null which returns null (neither true nor false). IS null is the right syntax.

Upvotes: 3

Related Questions