user3871760
user3871760

Reputation: 1

Calling user defined functions with Create Table in PostgreSql

I am getting an error while calling the user defined function while creating table in PostgreSql

Function is:

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;

Table is:

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

I am getting following error:

ERROR: syntax error at or near "AS"

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

entity_collector_team_team_code_seq its a sequence it generate sequence number like 1. After creation of table I am expecting output as T10001 and T10002 in sequence itself.

Thanks in Advance

Upvotes: 0

Views: 336

Answers (1)

user330315
user330315

Reputation:

Postgres does not have computed columns.

You probably meant to assign a default value to the column:

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

Upvotes: 1

Related Questions