Postgresql 选择常量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35616982/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 02:11:07  来源:igfitidea点击:

Postgresql Select Constant

sqlpostgresql

提问by Brett Brockway

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

在 Oracle 中,我可以选择一个常量值来填充列,如下所示:

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.

无论出于何种原因,当我尝试在 postgres 中执行此操作时,我收到此错误。

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

回答by Adrian Lynch

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