1

For example I want to do like this:

select id,name from first;  

It should look like this:

The Query Result // this should be the title of the query  
id name  
1  Ali  
2  Sami
0

2 Answers 2

9

If you use psql, you can change the field separator using \f and \a meta commands. I show an example below:

testdb=# SELECT * FROM first;
 id | name 
----+------
  1 | Ali
  2 | Sami
(2 rows)

testdb=# \f ','
Field separator is ",".

testdb=# \a
Output format is unaligned.

testdb=# SELECT * FROM first;
id,name
1,Ali
2,Sami
(2 rows)

And, \C meta command can be added any titles.

testdb=# \C 'The Query Result'
Title is "The Query Result".

testdb=# SELECT * FROM first;
The Query Result
id,name
1,Ali
2,Sami
(2 rows)
1
  • if you run psql with the --csv flag then you can skip \f and \a meta commands. dan@ubuntu:~$ psql --csv dan@db=# select * from first; id,name 1,Ali 2,Sam
    – Dan
    Jan 4 at 21:27
2

When using DBeaver, nowadays you can either use --name or --title in front of your SQL statement (closed with ;) to name your SQL query's result tab.

For example:

-- title: All active users
SELECT *
FROM users u
WHERE u.active = 1
ORDER BY u.created_at DESC

Just don't forget that you need to use "SQL Editor > Execute statements in separate tabs" for this to work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.