I'm trying to add a unique constraint to an existing table using the PSQL command line:
ALTER TABLE table_name ADD CONSTRAINT test_key UNIQUE (col1, col2);
The problem is that after I hit enter, nothing happens. I just get a new blank line without the command prompt, but the cursor is still there. I have to eventually hit ctrl+C to cancel the statement. Can anyone tell me what I'm missing?
It turns out it was running the script. There was nothing wrong with my script, it just didn't give me any indication it was running, other than me being able to enter in to new blank lines and the cursor blinking. It took a while but it eventually created the constraint.
Related
I first created a table, then I altered it. Just after alter command I am trying to view the tables by writing
show tables
command but it displays the error-
show is not valid at this position, expecting ADD, algorithm , ALTER,
Auto increment.......
I'm trying to drop a table from the PGadmin3 GUI, which means right click and then DROP TABLE. In few seconds PGadmin crash.
Similar happen if I use psql adopting the shell; here I write:
myDBname=> DROP TABLE my_table
and it returns,
myDBname->
(note the difference between => and ->)
It seems that nothing is happen. But if I write \dt the table is still there.
Anyone can help me?
At a relational database command prompt, normally if you enter a query, then you get data back, followed by a new command prompt. Postgresql does this for me too when I select from a table with no quotes in the name. I'm trying to debug the Postgresql setup for a sample Scala application that uses quoted table names, though, and when I select from one of these manually with psql, I get the data, but it is followed by text on an inverted-color background that says
(END)
instead of a new command prompt, and I can't seem to get the command prompt back. What's going on? I haven't found mention of this behavior of Postgresql anywhere.
I'm using a new install of Postgresql 9.3 on Ubuntu 14.04. Attempting to follow instructions in the book the above-linked sample application came from, I'm executing
CREATE TABLE "user" (
id bigserial PRIMARY KEY,
email varchar NOT NULL,
password varchar NOT NULL,
firstname varchar NOT NULL,
lastname varchar NOT NULL
);
Then I'm executing something in the sample application that through a lot of indirection ends up inserting a single row to this table. I don't think the details of this should be relevant. Then as a test I am manually executing the following in psql:
select * from "user";
This ought to be about as trivial as you can get. I'm an old hand at Oracle, but completely new to Postgresql. I see that using quoted names is considered bad practice by many, but I'm trying not to perturb the sample application any more than I have to.
How do I get my command prompt back?
After a query is returned and the results are being displayed, psql switches to a vi/less-like view of the results. Try hitting q to exit that view again and your command prompt should return.
We can return back to original terminal by giving Ctrl+C. This works for me in Psql Version 12.
I would like to change the name of my sequence I use. I tried those two options and failed:
ALTER TABLE PLAYER RENAME id_seq_player TO player_id_seq;
and
ALTER SEQUENCE id_seq_player RENAME TO player_id_seq;
I looked at the official documentation and from there I created those two SQL, but none of them worked. The first solution resulted in a SQL error and the second had a time out.
Here is the SQL error I get:
ERROR: column "id_seq_player" does not exist
********** Error **********
* UPDATE *
Seems like the second SQL statement did the job. Since I have to forward the port, maybe it was an issue with the connection or OpenShift. But now I retried several times to verify and it works.
ALTER SEQUENCE id_seq_player RENAME TO player_id_seq; /* Works */
ALTER SEQUENCE id_seq_player RENAME TO player_id_seq;
is correct. You might want to add the schema name as well to ensure you are altering the correct one, but this should most likely work.
If it timeouts, you might have another process that is locking your sequence. Is there a way for you to turn off all the other database users, or is it too critical to do so?
Try this:
ALTER TABLE id_seq_player RENAME TO player_id_seq;
Dont know the command line but you can change it on the pgAdmin
I just add 1 to my sequence and change it back.
How would I edit a trigger function in postgresql using psql? I have tried the using \ef trigger_name and every single time I try that it does not stick. Do I have to drop all of the triggers that refer to that trigger function before attempting to update it? I have been looking at the docs for a while and I did not find anything saying that I must to that? I have tried typing in the CREATE OR REPLACE... by hand into psql and that did not work.