Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8807147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:17:54+00:00 2026-06-14T02:17:54+00:00

I have the following line in a CREATE TABLE statement: field1_id bigint DEFAULT nextval(‘table1_field1_id_seq’::regclass)

  • 0

I have the following line in a CREATE TABLE statement:

field1_id bigint DEFAULT nextval('table1_field1_id_seq'::regclass) NOT NULL,

What does regclass mean in the above? Is it an absolute requirement to add ::regclass?

N.B: I had seen the Postgresql documentation link which tells about regclass, but couldn’t understand it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T02:17:55+00:00Added an answer on June 14, 2026 at 2:17 am

    No, you do not need the cast to regclass when calling a function like nextval that accepts a regclass parameter, as there is an implict cast from text to regclass. In some other contexts an explicit cast to regclass may be required.

    Explanation:

    ::regclass is a cast, like ::integer.

    regclass is a “magic” data type; it’s actually an alias for oid, or “object identifier”. See Object identifier types in the documentation. Casting to regclass is a shortcut way of saying “this the name of a relation, please convert it to the oid of that relation”. Casts to regclass are aware of the search_path, unlike querying pg_class for a relation’s oid directly, so casting to regclass isn’t exactly equivalent to subquerying pg_class.

    Tables are relations. So are sequences, and views. So you can get the oid of a view or sequence by casting to regclass too.

    There are implicit casts defined for text to regclass, so if you omit the explicit cast and you’re calling a function that accepts regclass the cast is done automatically. So you do not need it in, for example, nextval calls.

    There are other places where you may. For example you can’t compare text directly with oid; so you can do this:

    regress=> select * from pg_class where oid = 'table1'::regclass;
    

    but not this:

    regress=> select * from pg_class where oid = 'table1';
    ERROR:  invalid input syntax for type oid: "table1"
    LINE 1: select * from pg_class where oid = 'table1';
    

    Just for fun I tried to write a query that performed the equivalent operation of casting to regclass. Don’t use it, it’s mostly for fun, and as an attempt to demo what’s actually happening. Unless you’re really interested in how Pg’s guts work you can stop reading here.

    As I understand it, 'sequence_name'::regclass::oid is roughly equivalent to the following query:

    WITH sp(sp_ord, sp_schema) AS (
      SELECT 
        generate_series(1, array_length(current_schemas('t'),1)),
        unnest(current_schemas('t'))
    )
    SELECT c.oid
    FROM pg_class c INNER JOIN pg_namespace n ON (c.relnamespace = n.oid)
    INNER JOIN sp ON (n.nspname = sp.sp_schema)
    WHERE c.relname = 'sequence_name'
    ORDER BY sp.sp_ord
    LIMIT 1;
    

    except that it’s a lot shorter and a lot faster. See System information functions for the definition of current_schemas(...), etc.

    In other words:

    • Get a ab array listing all schemas we have access to and pair each entry up with an ordinal number for its position in the array
    • Search pg_class for relations with matching names and associate each with its namespace (schema)
    • Sort the list of remaining relations by the order in which their schemas appeared in search_path
    • and pick the first match
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table in MYSQL: CREATE TABLE 't001_prospeccao' ( 'pro_id' bigint(20) NOT
I use the following sql statement in mysql: CREATE TABLE User( userId int NOT
If I have the following SQL query CREATE TABLE #t1 (a INT NOT NULL
I have a computed column created with the following line: alter table tbPedidos add
I have the following example code: create table Details( name varchar(20), age int, weight
I have created the following table CREATE TABLE Customers( CustomerID varchar2(9) PRIMARY KEY, Customer_Contact
I have created the following table CREATE TABLE Customers( CustomerID varchar2(9) PRIMARY KEY, Customer_Contact
I have a table with the following column structure: sqlite> create table stocks(stockticker varchar(4),
I have the following table: if object_id(N'dbo.Node') is null create table dbo.Node ( ID
I have following line code in my view: <td> Model.some_instance_method(args) </td> I would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.