Brett Brockway
Brett Brockway

Reputation: 291

Postgresql Select Constant

In Oracle I can select a constant value that will populate down the column like this:

Select 
     "constant" constantvalue,
     orders.name
from 
     orders

and it will yield:

ConstantValue     Name
  constant       sandwich
  constant        burger

For whatever reason, when I try to do this in postgres I receive this error.

ERROR:  column "Constant" does not exist

here is my code

    select
        date_trunc('day', measurement_date + (interval '1 day' * (6 - extract(dow from measurement_date)))) week,
        "AROutstanding" colname,
        round(avg(Total_Outstanding),0) numbah
    from
                (
                select
                    measurement_date,

                    sum(cast(sum_of_dollars as numeric)) Total_Outstanding
                from
                    stock_metrics
                where
                    invoice_status not in  ('F','Write off')
                group by
                    measurement_date
                ) tt
            group by
                week

Upvotes: 29

Views: 33556

Answers (2)

Adrian Lynch
Adrian Lynch

Reputation: 8494

Change your double quotes to single quotes.

So this:

Select 
     "constant" as constantvalue,
     orders.name
from 
     orders

Should be this:

Select 
     'constant' as constantvalue,
     orders.name
from 
     orders

Upvotes: 41

RCRalph
RCRalph

Reputation: 384

For anyone confused by @Adrian Lynch's answer, I found out that doing

SELECT
    'constant' AS ConstantValue,
    orders.name
FROM
    orders

did the trick for me.

This could be used for numbers as follows: 1234 AS constantvalue.

Upvotes: 3

Related Questions