2014-11-24 93 views
0

而調用用戶定義的函數,而在PostgreSQL中創建表調用用戶自定義函數與PostgreSQL的

功能,我得到一個錯誤創建表是:

CREATE OR REPLACE FUNCTION nextval_special() 
    RETURNS text AS 
SELECT 'T'||to_char(nextval('entity_collector_team_team_code_seq'), 'FM10000') 

LANGUAGE sql VOLATILE 

COST 100; 

表是:

CREATE TABLE testtable1 
(
id integer, 
    teamcode AS (dbo.nextval_special()) 
) 

我收到以下錯誤:

ERROR: syntax error at or near "AS"

LINE 4: teamcode AS (dbo.nextval_special())

entity_collector_team_team_code_seq其序列它產生的序列號像1 創建表後,我期待輸出爲序列本身T10001和T10002。

在此先感謝

回答

1

Postgres沒有計算列。

你可能意味着一個默認值分配給列:

CREATE TABLE testtable1 
(
    id  integer, 
    teamcode text not null default dbo.nextval_special() 
); 
+0

正確的。 – 2014-11-25 04:53:05