postgresql - losing command prompt after select from quoted table name - postgresql

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.

Related

Sqlite dump outputting tables out of order

I'm trying to convert a Sqlite3 database to Postgres by dumping it to raw SQL, editing the SQL and then loading it via psql, summarized by this script.
The overall approach seems fine, except for one problem. When I try to run the final load with psql, I get errors like "table x does not exist", because Sqlite is outputting tables referred to by foreign keys after the tables that refer to them. This causes psql to abort all further statements with the message:
ERROR: current transaction is aborted, commands ignored until end of transaction block
The only immediately solution I see is to manually go through all the SQL and try to manually reorder the CREATE TABLE commands so that the proper order is maintained. However, this is very tedious.
Is there any way to force Sqlite to output SQL so that tables are output in order of dependency?

Back tick not working to escape "Order" in Google Cloud SQL

Is there some reason (maybe a setting) that Google Cloud SQL fails to escape "Order" when using back ticks, but does work on other reserved words?
In one instance of Google Cloud SQL, the following command is successful:
CREATE TABLE `Order`
(
Test CHAR(1) NULL
);
In a different instance, recently created under a new App Engine, I get the following error:
Error Code: 1005. Can't create table 'roms.Order' (errno: 150)
However, in the same instance, escaping "ORDER" or "order" does work to create table.
Thanks for any suggestions.
After I dropped and recreated the database, I was able to create the Order table.
The very first time I tried to create the Order table, there was failure (I believe a connection error). I am thinking the table was partially created and not rollback back properly after the failure. Causing any subsequent creation attempts to fail.
The table was never shown the schema and drop table did not work.

How to View Execution Plan for Query Containing a Temp Table in Toad for SQL Server?

I am trying to tune the performance of a stored procedure that contains a temp table in Toad for SQL Server. After selecting "Include Actual Execution Plan" from the 'Editor' menu, I run the query. The Results Set returns values as expected, however, the Execution Plan tab shows the following error:
Invalid object name '#temp'.
I have tried creating the temp tables first then just executing the SELECT statement that references it, I tried creating the temp tables as global temp tables and running the SELECT statement in another window, and I have messed with the SHOWPLAN_TEXT and STATISTICS PROFILE (as mentioned in this question) but I keep receiving the same error. The only thing I have not tried is using a table variable, but the changes I will be making cannot be done on table variables, so this is not really an option for me at this time.
Has anyone else come across this or have any ideas as to what I might be doing wrong?
You'll want to use the ISQL command line utility on a machine that has SQL Server client package installed. Or any other utility that can submit a query to SQL Server.
ISQL Docs and How to get an execution plan (2nd part of the post)

Table invisible in PostgreSQL - Undefined relation issue at different sessions

I have executed the following create statement using SQLWorkbench at my target postgresql database:
CREATE TABLE Config (
id serial PRIMARY KEY,
pub_ip_range_low varchar(100),
pub_ip_range_high varchar(100)
);
Right after table creation I request the table content by typing 'select * from config;' and see that table could be retrieved. Nevertheless, my java program that uses JDBC type 4 driver cannot access the table when I issue the same select statement in it. An exception is thrown when the program tries to access it which says says "Undefined relation" for the config table.
My questions are:
Why sqlworkbench where I had previously run the create statement recognizes the table while my java program cannot find it?
Where does the postgressql DBMS puts the tables I created? I don't see them neither in public nor in information schema.
NOTE:
I checked target postgres database and cannot see the table Config anywhere although SQL workbench can query it. Then I opened another SQL workbench instance and noticed that the table cannot be queried (i.e. not found). So, my conclusion is that PostgreSQL puts the table I created in the first running SQLBench instance into some location that is bound to that session. Another SQL Workbench instance or my java program is not bound to session, so cannot query the previously created table config.
The only "bloody location" that is session-local in PostgreSQL is the schema pg_temp, in other words: temporary tables. But your CREATE command does not display the keyword TEMP[ORARY]. Of course, as long as the transaction is not commited, nobody sees anything outside the transaction.
It's more likely you are seeing a switcheroo of hosts / databases / ports / or the schema search_path. A mixup with the mixed-case table name is a hot candidate, too. If you don't double-quote "Config", the table ends up all lower case in the system, so: config. If you later double quote the name, it won't match. The manual has the details.
Maybe the create failed on the extra trailing comma?
CREATE TABLE config (
id serial PRIMARY KEY,
pub_ip_range_low varchar(100),
pub_ip_range_high varchar(100) -- >> ,
);

Creating Multiple table in Oracle

I am using Oracle Express 10g and I'm enter the following text to create 2 tables in the sql command line, but it is not working.
CREATE TABLE student (
matric_no VARCHAR2(8),
first_name VARCHAR2(20),
last_name VARCHAR2(20),
date_of_birth DATE
);
CREATE TABLE student1 (
matric_no VARCHAR2(8),
first_name VARCHAR2(20),
last_name VARCHAR2(20),
date_of_birth DATE
);
Can anyone see what I am doing wrong.
Thanks
By "command line" you probably mean the web application that comes with Oracle Express 10g. This application has several browser incompatibilities and is basically unable to execute several statements at once (also see Oracle 10g - invalid character on DB importing).
Either put your statements in a text file and upload them as a SQL script. Or switch to a better tool such as SQL Developer (downloadble from Oracle web site).
Are you sure you didn't type this out in WORD?
Sometimes there are problems with "invisible" characters. For example if you hit TAB in WORD, it will store it as a special character which will thereby cause an error when you try running it in SQLPlus.