Reputation: 63
I am pretty new in PostgreSQL and only know basic operations about database. I have a database called neuro_db with username neuro_user. Now I found I cannot delete a column in a table from neuro_db.
After I tried psql neuro_db
in ubuntu 14.04, I got in a command line started with neuro_db=#
. The \d
command would show a table like this:
List of relations
Schema | Name | Type | Owner
--------+-----------------------------------+----------+------------
public | auth_group | table | neuro_user
public | auth_group_id_seq | sequence | neuro_user
public | auth_group_permissions | table | neuro_user
public | auth_group_permissions_id_seq | sequence | neuro_user
public | auth_permission | table | neuro_user
public | auth_permission_id_seq | sequence | neuro_user
public | auth_user | table | neuro_user
public | auth_user_groups | table | neuro_user
public | auth_user_groups_id_seq | sequence | neuro_user
public | auth_user_id_seq | sequence | neuro_user
public | auth_user_user_permissions | table | neuro_user
public | auth_user_user_permissions_id_seq | sequence | neuro_user
public | django_admin_log | table | neuro_user
public | django_admin_log_id_seq | sequence | neuro_user
public | django_content_type | table | neuro_user
public | django_content_type_id_seq | sequence | neuro_user
public | django_migrations | table | neuro_user
public | django_migrations_id_seq | sequence | neuro_user
public | django_session | table | neuro_user
public | neuro_category | table | neuro_user
public | neuro_category_id_seq | sequence | neuro_user
public | neuro_page | table | neuro_user
public | neuro_page_id_seq | sequence | neuro_user
(23 rows)
I wanted to edit the table "neuro_page" and after typing \d neuro_page
, it will show this table:
Table "public.neuro_page"
Column | Type | Modifiers
-------------+------------------------+---------------------------------------------------------
id | integer | not null default nextval('neuro_page_id_seq'::regclass)
category_id | integer | not null
title | character varying(128) | not null
text | text | not null
url | character varying(200) | not null
photo | character varying(100) | not null
order | character varying(128) | not null
date | date | not null
views | integer | not null
likes | integer | not null
I wanted to delete the "order" column in this table so I tried typed ALTER TABLE neuro_page DROP COLUMN order
right after the neuro_db=#
line, but nothing happened. There was also nothing after trying ALTER TABLE neuro_page
and DROP COLUMN order
respectively. The "order" column is still there! And no error information!
I have also searched on google for the answer but found nothing. I think I have followed the normal operations in database but can not drop a single column in a table. There is no foreign key for "order" column.
I'd be very greatful if anyone can help me with this issue. Thanks!
Upvotes: 2
Views: 6257
Reputation: 308939
You need to escape the column name order in backticks because order is a keyword (e.g. order by 'column_name'
). Make sure you are using a semicolon to show the end of the command:
ALTER TABLE neuro_page DROP COLUMN `order`;
Upvotes: 1