Why is the "CREATE DATABASE" command not working? [duplicate] - postgresql

This question already has answers here:
In psql, why do some commands have no effect?
(2 answers)
Closed 11 months ago.
When I try to use SQLSHELL "CREATE DATABASE test". I don't get a prompt that anything was created (not sure if i'm supposed to). Then when I check to see if it was created ("\l"). Nothing is there.
What is happening?

You have to terminate SQL commands with ;.
In your case:
CREATE DATABASE test;

Related

I can't drop a database in PostgreSQL 11 [duplicate]

This question already has answers here:
In psql, why do some commands have no effect?
(2 answers)
Closed 3 years ago.
I have 5 databases which are shown below.
I am trying to drop test database by using "drop database test". But when i check list of databases than test database also shown in that list.
What should I do now?
How i can resolve this issue?
Yeah you are missing the semi-colon. When psql changes from = to - in the prompt, it means you haven’t finished the query.

Is it possible to use a for loop in postgresql (Function) [duplicate]

This question already has answers here:
Postgres FOR LOOP
(6 answers)
Closed 4 years ago.
Is it possible to use a for loop in postgresql (Function)
In a word - yes. The syntax is quite simple and straightforward:
FOR i IN 1..10 LOOP
-- Do something with i
END LOOP;
You can also go backwards (by using the REVERSE keyword before specifying the range) and control the size of the step by using a BY clause.
See the documentation for the complete details.

Is there any way to print out debug statements in Postgres PSQL? [duplicate]

This question already has answers here:
printing a value of a variable in postgresql
(2 answers)
Closed 5 years ago.
I'm thinking something in the lines of DBMS_OUTPUT.PUT_LINE in Oracle, it allows you to trace what's going on in a stored procedure in the exactly same way you would use printf, puts or some other STDIO writing proc in a "normal" programming language, i.e.
DBMS_OUTPUT.PUT_LINE('I got here:'||:new.col||' is the new value');
is there any way of doing this in Postgres?
If not, what's the "community way" of doing this? Creating a table with a string row and inserting debug values there?
You can use RAISE NOTICE like this:
RAISE NOTICE 'I got here:% is the new value', NEW.col;

how to change character length in execute file for postgresql [duplicate]

This question already has answers here:
pgAdmin: How to see complete value in a cell in output
(1 answer)
pgAdmin III faulty behavior?
(2 answers)
Closed 5 years ago.
I have a view in my database (PostgreSQL) and I would like to see it's code.
I wrote this query:
select definition from pg_views where viewname='x'
this works most of the time, However in some of the views when the select code is long I get at some point (...)
for example this is one of the results of query where it shows (...):
" SELECT f.selectid,
a.clientid,
a.orderid,
a.clientname,
c.part,
c.product,
c.okey,
e.contry,
d.city,
(
CASE
WHEN (b.dateofissue IS NULL) THEN
CASE
(...)"
This is only part of the code... Why it doesn't show me the whole code?
In pgAdmin III, under Query tool options:
pgAdmin Query tool Options
You want pg_get_viewdef, but I suspect you'll have the same issue there. The problem is probably that the client application is truncating the returned query.
If you're using PgAdmin-III this is in the FAQ.
If you're using psql this shouldn't happen.

How to get the Current Computer name or terminal name in PostgreSQL? [duplicate]

This question already has an answer here:
Find the host name in postgresql [duplicate]
(1 answer)
Closed 9 years ago.
I Need a Query of getting the Current Computer name or Terminal Name using PostgreSQL Database
Please Give me the solution ASAP
Below may work for your needs. If you are on the console be careful with the results, likely you don't want to kill a postgres owned process.
SELECT inet_client_addr();
SELECT * FROM pg_stat_activity
WHERE client_addr = inet_client_addr();
*http://bytes.com/topic/postgresql/answers/423851-retrieve-ip-client-postgres
*http://postgresql.1045698.n5.nabble.com/How-to-stop-a-query-td1924086.html