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

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.

Related

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

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;

Why after the UPDATE operation in PostgreSQL the row goes to the last place? [duplicate]

This question already has answers here:
Why postgres returns unordered data in select query, after updation of row?
(2 answers)
Postgresql: row number changes on update
(1 answer)
What is the default select order in PostgreSQL or MySQL?
(4 answers)
Different Default ordering between ORACLE and PostgreSQL
(1 answer)
Closed 2 years ago.
I had this question on the job interview in some smell company. Now I understand that it's a wrong question itself.
My suggestion was that the PostgreSQL is copying the row and then deleting the previous one, i.e. using transaction, and then sorting rows by system hidden index.
They said that it's not a right answer, but they didn't say the right answer anyway because the interview was like a ping-pong with a high speed in one direction.
I've asked guys from core-team who make PostgreSQL in IRC. They said that the result order could be unpredictable and gave me documentation of PostgreSQL in very low-level in C so I didn't understand anything.
Now I found this statement https://www.postgresql.org/docs/current/sql-select.html :
If the ORDER BY clause is specified, the returned rows are sorted in
the specified order. If ORDER BY is not given, the rows are returned
in whatever order the system finds fastest to produce. (See ORDER BY
Clause below.)
Okay, but what if we use very simple table without any relations in the scheme, like
USER (id, name). What the point is there? Why the updated row would be on the last place? What should I answer on the interview?
First of all, not only PostgreSQL, but all other databases, the order of tuples isn't guaranteed. When you do insertion, each tuple is been written to page in PostgreSQL. Then, the page will be written into the disk and following the corresponding file system mechanism. The newly updated row isn't necessary to be the last place, unless the ORDER BY is specified. The reason the newly updated row appear at the last place, that might be the fact of LRU replacement policy is been adopted in that file system.

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.

How to handle single quotes in Postgresql query [duplicate]

This question already has answers here:
Insert text with single quotes in PostgreSQL
(8 answers)
Closed 7 years ago.
When I am trying to find all records in details table which have Linux present in the array column operating_systems.
Query select * from details where 'Linux' = ANY(operating_systems); works perfectly and returns all records which have Linux in operating_systems column.
But if I want to get all records where I don't know is present in operating_systems I am unable to form a correct query.
Query select * from details where 'I don\'t know' = ANY(operating_systems); does not escape single quotes and takes it literally, resulting in an incomplete query.
Found that single quotes can be escaped by adding another single quote before it. So select count(*) from details where 'I don''t know' = ANY(operating_systems); works.
This is acceptable for ad-hoc queries, or queries where a data literal is hard coded.
It's absolutely not OK if the string comes from an application user. Do not do this. See http://bobby-tables.com/ for why.
Use parameterised queries (often incorrectly called prepared statements, though they're not quite the same thing). Exactly how to do that depends on your programming language and client, which you have not mentioned, but it usually involves "preparing" a statement then executing it with parameters.
Found that single quotes can be escaped by adding another single quote before it. So select count(*) from details where 'I don''t know' = ANY(operating_systems); works.

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