0

What is the way to achieve expected result from psql select:

SELECT 'Hello world';

using this in SQuirreL I get value: in unnamed column. What is the way to get string Hello world as a result?

I want to use this approach to format outputs using commas, colons, etc. Is there another way to pre-prepare results for further usage?

Thanks in advance for any help

Václav
  • 365
  • 2
  • 15
  • What do you mean by *...to get string Hello world as a result...*? You want it to be a column name or something else? Apart from that use RDBMS to process and fetch necessary data and client code to format and present that data. – peterm Oct 02 '13 at 07:56
  • I want get one column with 'Hello word' as its content. Column name is unset here (in squirrel '?column?') – Václav Oct 02 '13 at 08:01

4 Answers4

1

I want get one column with 'Hello word' as its content. Column name is unset here (in squirrel '?column?')

It's because you didn't give that column a name (alias)

If you'll do it like this

SELECT 'Hello world' AS column_name

you'll get

| COLUMN_NAME |
|-------------|
| Hello world |

Here is SQLFiddle demo

peterm
  • 91,357
  • 15
  • 148
  • 157
  • Thaks, column name change works but its not an issue, column data is still '' in my case. I use psql 8.4. I'm not able to get SQLFiddle working with psql 8.4.(it writes something about connection error). – Václav Oct 02 '13 at 08:25
  • Here is working [sqlfiddle](http://sqlfiddle.com/#!10/d41d8/132) with postgres 8.3. Try another client if squirrel is giving you this. – peterm Oct 02 '13 at 08:27
  • You are right it works, it is some SQuirreL issue, using psql client I get the same as on SQLFiddle. Thaks – Václav Oct 02 '13 at 08:35
  • You're quite welcome :) If you feel like the answer was helpful please, consider to **[accept](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)** it. – peterm Oct 02 '13 at 08:36
1

This is an old question, but I ran into the same problem with SQuirreL, and found a simple work-around. Try this in SQuirreL:

SELECT trim('Hello world') AS column_name;

Actually, any of the PostgreSQL string functions will work, like upper(), lower(), etc., depending on your needs.

John Black
  • 621
  • 4
  • 9
0

The question is not clear but I give you the possible optionsin one block

begin
    declare @PreDefinedVariable nvarchar(50)
    Select @PreDefinedVariable = 'Hello World!'
    select @PreDefinedVariable as [Result]
end

Govin
  • 99
  • 1
  • 2
0

It is an SQuirreL SQL Client issue, using psql from bash I get expected:

tdb14=> SELECT 'Hello world' AS column_name;
 column_name 
-------------
 Hello world
(1 row)
Václav
  • 365
  • 2
  • 15