pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: grumpylittleted@googlemail.com
Subject: BUG #16909: On update (not insert) the attisdropped flag is set for tables which are recreated with the same col
Date: Tue, 02 Mar 2021 10:34:55 +0000
Message-ID: <16909-3a6da1ab19f5652b@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      16909
Logged by:          Grumpylittleted
Email address:      grumpylittleted@googlemail.com
PostgreSQL version: 13.2
Operating system:   Linux 5.8.0-44-generic #50~20.04.1-Ubuntu S
Description:        

/*

  BUG:

  Using 13.2
  On update (not insert) the attisdropped flag is set for tables which are
recreated with the same column names as the original but where preceding
columns have been dropped

  METHOD:
  Create a table t with more than two columns: x, y, z
  Drop that table
  Create a table t with a subset of the columns with the same name as the
previous table: here we remove y
  Insert a new row: there are two attributes (correct), neither of which
have the attisdropped flag set (correct) (so bug not apparent with
inserts)
  Update the row: there are two attributes (correct), the first attribute
has the attisdropped flag unset (correct) BUT the second attribute has the
attisdropped flag set (incorrect)



  make 
  sudo cp ./f.so `pg_config --pkglibdir`


  SQL:

  create or replace function f() returns trigger as './f.so','f' language c
strict;

  drop table if exists t cascade;
  create table t(x int, y int, z int);

  drop table t cascade;
  create table t(x int, z int);
  create trigger tf before insert or update on t for each row execute
procedure f();
  insert into t values(4,5); -- attr num=1 attisdropped=0
  update t set x=2;




*/

#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include "postgres.h"
#include "fmgr.h"
#include "executor/spi.h"
#include "commands/trigger.h"
#include "utils/rel.h"
#include "utils/fmgrprotos.h"



PG_MODULE_MAGIC;
PG_FUNCTION_INFO_V1( f );
Datum f( PG_FUNCTION_ARGS ) {

  TriggerData *trigdata = ( TriggerData * ) fcinfo->context;
  const TupleDesc tupdesc = trigdata->tg_relation->rd_att;
  HeapTuple tuple = TRIGGER_FIRED_BY_UPDATE( trigdata->tg_event ) ?
trigdata->tg_newtuple : trigdata->tg_trigtuple;

  for( int i = 1; i <= tupdesc->natts; i++ ) {
    elog( INFO, "attr num=%d attisdropped=%d", i, TupleDescAttr( tupdesc, i
)->attisdropped );
  }

  return PointerGetDatum( tuple );

}



view thread (4+ messages)  latest in thread

Message-ID: <16909-3a6da1ab19f5652b@postgresql.org>
Permalink:  ../16909-3a6da1ab19f5652b@postgresql.org/
Also on:    postgresql.org/message-id/16909-3a6da1ab19f5652b@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, grumpylittleted@googlemail.com
  Subject: Re: BUG #16909: On update (not insert) the attisdropped flag is set for tables which are recreated with the same col
  In-Reply-To: <16909-3a6da1ab19f5652b@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox