0

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

1 Answer 1

1

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()
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.