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
1

2 Answers

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
3

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.

2

Your Answer

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

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest