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
                Defining constantsFirst, specify the name of the constant. The name should be as descriptive as possible. Second, add the constant keyword after the name and specify the data type of the constant. Third, initialize a value for the constant after the assignment operator ( := ).
In PostgreSQL, the select into statement to select data from the database and assign it to a variable. Syntax: select select_list into variable_name from table_expression; In this syntax, one can place the variable after the into keyword.
The purpose of unnest function in PostgreSQL is to expand the array into rows. Unnest function generates a table structure of an array in PostgreSQL. Unnest array function is beneficial in PostgreSQL for expanding the array into the set of values or converting the array into the structure of the rows.
The PostgreSQL SELECT statement retrieves data from a single or several tables in a database, and returns the data in a result table, called a result-set. Use the SELECT statement to return one or more rows matching the specified criteria from the database tables.
Change your double quotes to single quotes.
So this:
Select 
     "constant" constantvalue,
     orders.name
from 
     orders
Should be this:
Select 
     'constant' constantvalue,
     orders.name
from 
     orders
                        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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With