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 7770467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:25:01+00:00 2026-06-01T16:25:01+00:00

I am developing a framework that dynamically creates tables for contents storage on PostgreSQL

  • 0

I am developing a framework that dynamically creates tables for contents storage on PostgreSQL 9.1. One of the API functions allows caller to save a new contents entry by specifying all fields within a given object (say, web form). In order to receive a set of fields framework creates a composite type.

Consider the following code:

CREATE SEQUENCE seq_contents MINVALUE 10000;
CREATE TABLE contents (
    content_id      int8        not null,
    is_edited       boolean     not null default false,
    is_published    boolean     not null default false,
    "Input1"        varchar(60),
    "CheckBox1"     int2,
    "TheBox"        varchar(60),
    "Slider1"       varchar(60)
);
CREATE TYPE "contentsType" AS (
    "Input1"        varchar(60),
    "CheckBox1"     int2,
    "TheBox"        varchar(60),
    "Slider1"       varchar(60)
);
CREATE OR REPLACE FUNCTION push(in_all anyelement) RETURNS int8 AS $push$
DECLARE
    _c_id   int8;
BEGIN
    SELECT nextval('seq_contents') INTO _c_id;

    EXECUTE $$INSERT INTO contents
    SELECT a.*, b.*
      FROM (SELECT $1, true, false) AS a,
           (SELECT $2.*) AS b$$ USING _c_id, in_all;

    RETURN _c_id;
END;
$push$ LANGUAGE plpgsql;

Now, in order to call this function I have to add explicit cast, like this:

SELECT push(('input1',1,'thebox','slider1')::"contentsType");

Is there a way to avoid explicit cast? As I would like external callers not to deal with casts, i.e. hide the logic behind the PostgreSQL functions. Currently I have such error:

SELECT push(('input1',1,'thebox','slider1'));
ERROR:  PL/pgSQL functions cannot accept type record
CONTEXT:  compilation of PL/pgSQL function "push" near line 1
  • 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-01T16:25:02+00:00Added an answer on June 1, 2026 at 4:25 pm

    Have you considered passing the record variable as its text representation?
    In theory, every record variable can be cast to and from text with the normal CAST operator.

    Here is the function modified so that in_all has type text and gets casted to "contentsType" in the USING clause:

    CREATE OR REPLACE FUNCTION push(in_all text) RETURNS int8 AS $push$
    DECLARE
        _c_id   int8;
    BEGIN
        SELECT nextval('seq_contents') INTO _c_id;
    
        EXECUTE $$INSERT INTO contents
        SELECT a.*, b.*
          FROM (SELECT $1, true, false) AS a,
               (SELECT $2.*) AS b$$ USING _c_id, in_all::"contentsType";
    
        RETURN _c_id;
    END;
    $push$ LANGUAGE plpgsql;
    

    Then it can be called like this (no explicit reference to the type)

    select push( '(input1,1,thebox,slider1)' );
    

    or like that (explicit record casted to text)

    SELECT push(('input1',1,'thebox','slider1')::"contentsType"::text);
    

    That would work not just with “contentsType”, but any other record type, assuming the function is able to convert it back to that type.

    Also in plpgsql, I assume this should work as well:

       ret := push(r::text);
    

    when r is a record variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a framework that, as one of its features, enables robots to use
I'm developing a zend framework application that includes a simple email function. The development
I am developing a Compact Framework application that needs to manipulate an existing MS
I'm developing a mobile site using IUI . It's a framework that makes web
We've been developing a web application (PHP, using the Yii PHP framework) that is
I'm developing a Cocoa/Obj-C application that involves a WebView (from the WebKit framework). I've
I am developing a C# application with .NET Framework 2.0. The problem is, that
I'm developing a framework which programs parts of itself dynamically after creating ER-Diagrams in
I'm developing a zend framework app that's just going to act as a web
I am developing an application framework that will be utilized by Silverlight on the

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.