2016-02-25 65 views
5

在Oracle我可以選擇一個恆定值將填充下來這樣的列:PostgreSQL的選擇恆

Select 
    "constant" constantvalue, 
    orders.name 
from 
    orders 

,它會產生:

ConstantValue  Name 
    constant  sandwich 
    constant  burger 

無論出於何種原因,當我嘗試在postgres中執行此操作我收到此錯誤。

ERROR: column "Constant" does not exist 

這裏是我的代碼

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

嘗試單引號。 –

+1

單引號是在SQL中表示常量字符串值的正確方法(並且它們可在任何數據庫中使用)。我認爲這是一個簡單的印刷錯誤。 –

回答

8

更改您的雙引號爲單引號。

所以這個:

Select 
    "constant" constantvalue, 
    orders.name 
from 
    orders 

應該是這樣的:

Select 
    'constant' constantvalue, 
    orders.name 
from 
    orders 
+0

謝謝,這工作。我以爲我嘗試過,但顯然不是:) –

+1

從一個數據庫移動到另一個數據庫總是很痛苦。我從MSSQL到MySQL,我一直在搜索答案! –