Dbeaver - run all query without selecting it (CTEs) - dbeaver

Is it possible to run the whole SQL query with all CTEs without selecting the code?
eg:
with CTE1 as (..),
CTE2 as (..),
..
CTE30 as (..),
select * from CTE30;
What I want is to have the cursor at last line and ctrl+enter and runs the code without me selecting it. (In datagrip its possible. )

Related

How to "PERFORM" a CTE query returning multiple rows/columns?

As a follow-up to this question:
How to "PERFORM" CTE queries in PL/pgSQL?
I try:
perform (with test_as_cte as(select * from myTable) select * from test_as_cte);
But get the following error:
SQL Error [42601]: ERROR: subquery must return only one column
Where: PL/pgSQL function inline_code_block line 9 at PERFORM
If I replace * with myCol in the above code there is no error.
However, I need to do realistic performance testing with the CTE and return multiple columns.
The WITH query enclosed in parentheses is treated like a sub-select. It works fine the way you have it as long as it returns a single value (one column of one row). Else you must treat it as subquery and call it like this (inside a PL/pgSQL code block!):
PERFORM * FROM (with test_as_cte as (select * from b2) select * from test_as_cte t) sub;
Or just:
PERFORM FROM (<any SELECT query>) sub;
The manual:
PERFORM query;
This executes query and discards the result. Write the query
the same way you would write an SQL SELECT command, but replace the
initial keyword SELECT with PERFORM. For WITH queries, use
PERFORM and then place the query in parentheses. (In this case, the
query can only return one row.)
I think this could be clearer. I'll suggest a fix for the documentation.

DBeaver changes format of Redshift views

everytime I create a view in Amazon Redshift using the Tool "DBeaver" - it totaly meeses up my SQL-Code.
Is there any reason for this?
with CTE1 as (
SELECT DISTINCT
No_
FROM
snapshots."_de_contract_header"
) Select * From CTE1
Right now I'm creating a View in Dbeaver using the create or Replace View Command
Create or Replace view snapshots.TEST as
with CTE1 as (
SELECT DISTINCT
No_
FROM
snapshots."_de_contract_header"
) Select * From CTE1
When I try to view the source-code of this view , it looks like this:
With smaler statements like this it's no problem - functionality is the same. But if statements get bigger and more complex it's nearly impossible to read the source code. Any Ideas?
That's not dbeaver, that's your database (Redshift). It's rewritting the SQL into something it can run. It always does this with queries, behind the scenes.
Store your view in a .sql file and reference that, not the printout from dbeaver.

Execute query within query (PostgresAdmin III)

I have a very long cleaning procedure with 1000s of "replaces".
I saved this in a separate file.
All other processes are defined in another query.
I would like to execute the cleaning file from the main query.
Is this possible and how to do that?
Example:
Main query file
create table a as
select * from b;
--a lot of other stuff--
execute cleaning query here!! -- I want to execute the cleaning query within my main query
-- cleaning query looks as follows (don't want to paste this into main query):
create table a_ as
select *, replace(replace(replace(...(a1
, 'WORD1', '')
, 'WORD2', '')
, 'WORD3', '')
... from a ;
-- end of cleaning query
--again a lot of stuff --
I suggest you using a trigger. PostgreSqlDocumentation: trigger
A trigger allows you to call functions (query); you can also declare it for each row so you can write a query which refers to only one generic row, than the trigger will apply it to every row of the table (you can also ask for a condition to be fulfilled)

PostgreSql command to see the table data

I am new in PostgreSql. I import the database on my linux machine. I am able to see the list of tables using \d command (GSM_test_db-# \d default_msg_details) its displaying the table list but I want to see the table data.
Any Command that shows table Data also Please tell me.
I already used select query GSM_test_db-# SELECT * FROM default_msg_details but its not displaying anything and its not giving any error.
Please tell me if any command or why this select its not displaying anything.
Because you need to terminate your statement with a ;
Try SELECT * FROM "default_msg_details";
Beside adding ";" at the end of your query, you also need add the quotes("") to your tabel's name as well.
Firstly, you need to disable pagination but retain the output:
\pset pager off
Then, use the below query:
SELECT * FROM "default_msg_details";

PostgreSQL and pgadmin3.exe

I am trying to start playing with postgres and found a very strange thing, I created a table using pgadminIII named testtable and added couple of column then I wrote following query in query editor
SELECT * from testtable;
it responded no table found with such name, then after that I tried
select * from "testtable"
with quotes(later one) it worked, then I dropped the table and created the table using script editor, with same name making it sure no quotes are around the name, then both query started working, I can't understand stand what that exactly mean, even if I write "teablename" in create table statement quotes shouldn't become the part of the table name.
Also, how can I make sure while using pgAdmin graphical user interface that all object get created without quote (of course if above problem because of that)?
Update: Environment Info
OS => Windows Server 2008 x64, Postgres => 9.0.3-2 x64, pgAdmin => >
Version 1.12.2 (March 22, 2011, rev:>
REL-1_12_2)
Did you use the new table dialog the first time? You shouldn't use quotes in the dialog as pgAdmin will insert all necessary quotes.
Edit
I discovered something today what is a little weird and might explain what happened to you.
When you do not quote a table name the table name it is converted to lowercase. So if you do
CREATE TABLE TestTable ( ... );
Your table will be called testtable
What happens when you start to query the table is this:
SELECT * FROM TestTable; -- succeeds looks for testtable
SELECT * FROM testtable; -- succeeds
SELECT * FROM "TestTable"; -- fails because case doesn't match
Now if you had done:
CREATE TABLE "TestTable" ( ... );
Your table would actually be called TestTable with the case preserved and the result is
SELECT * FROM TestTable; -- fails looks for testtable
SELECT * FROM testtable; -- fails
SELECT * FROM "TestTable"; -- succeeds