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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:23:23+00:00 2026-06-06T00:23:23+00:00

postgres 9.2 supports json columns. what would be best way to extend postgres to

  • 0

postgres 9.2 supports json columns. what would be best way to extend postgres to automatically index based on a json colum.

for example,

create table obj(
   obj_id    bigserial    primary key,
   col1      varchar(20),
   col2      date,
   obj       json
);
create index obj_col1 on obj( col1 );
create index obj_col2 on obj( col2 );

when the record is inserted or updated, col1 and col2 are set from the obj column.

essentially the rule is that any attribute, aside from primary key and json column itself, are automatically set from json object.

as a correllary, renaming col1 would also update the json attribute, renaming col1 there to the new name.

could be done using catalogue and execute statements, but would be slow as sin.

could be done by creating triggers for each table, but that’s both tedious and error prone.

cannot be accomplished through inheritance, since triggers cannot be inherited.

is an extension the best way to go? what would it even look like?


ends up cannot write extension to do this since pg does not support triggers on CREATE TABLE or ALTER TABLE.

the only suggestion for a kludge would be log for DDL, monitor the log, and then run a procedure. while this can be done, what we really need are triggers on CREATE and ALTER TABLE.

  • 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-06T00:23:25+00:00Added an answer on June 6, 2026 at 12:23 am

    It’s not clear to me how you derive “col1” from your json. Presumably it depends on your json.

    Anyway – the best approach is to write a script that writes your triggers for you, and another that writes the column-rename operation for you. You supply whatever parameters are necessary and it spits out plpgsql code.

    Oh – you may find http://pgtap.org/ useful too – you’ll want to test all this.

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

Sidebar

Related Questions

postgres has an array data type, in this case a numeric array: CREATE TABLE
I have a pretty primitive table schema now ( in Postgres ): CREATE TABLE
I am using Postgres 9.1 and would like to create a sequence which I
Since Postgres can only add columns at the end of tables, I end up
Using Postgres, I'm trying to use AUTO_INCREMENT to number my primary key automatically in
I have a Postgres instance building a GIN index. It's looking at about 200,000
I'm coming to Postgres from Oracle and looking for a way to find the
I'm interested to find out which ORM has best support for Postgres SQL database?
I'm using postgres, and I have a users table which contains users first and
I have a table that I would like to be able to present ranked

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.