Postgresql: Is it possible to dynamically loop through a table's column?

Take a look at the information_schema, there is a view "columns". Execute a query to get all current columnnames from the table that fired the trigger: SELECT column_name FROM information_schema. Columns WHERE table_schema = TG_TABLE_SCHEMA AND table_name = TG_TABLE_NAME Loop through the result and there you go!

More information can be found in the fine manual.

Take a look at the information_schema, there is a view "columns". Execute a query to get all current columnnames from the table that fired the trigger: SELECT column_name FROM information_schema. Columns WHERE table_schema = TG_TABLE_SCHEMA AND table_name = TG_TABLE_NAME; Loop through the result and there you go!

More information can be found in the fine manual.

Thank you very very much, I will look into it........ – Sayem Ahmed Jun 21 '10 at 11:25.

From 9.0 beta2 documentation about WHEN clause in triggers, which might be able to be used in earlier versions within the trigger body: OLD. * IS DISTINCT FROM NEW. * or possibly (from 8.2 release notes) IF row(new.

*) IS DISTINCT FROM row(old. *).

Yes. If all you're doing is testing whether any column values have changed and you don't need to know the specific column(s) that have changed, Stephen's 2nd snippet is definitely the way to go. Concise and never needs maintenance!

– j_random_hacker Jun 21 '10 at 15:28 Archangel might find it useful to combine that test with knowledge of whether Locked > 0 and whether locked has changed. Additionally IS DISTINCT FROM deals with nulls in a less surprising way than – Stephen Denne Jun 21 '10 at 20:54.

Use pl/perl or pl/python. They are much better suited for such tasks. Much better.

You can also install hstore-new, and use it's row->hstore semantics, but that's definitely not a good idea when using normal datatypes.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions