0

I have a variable A with the name of a column from table TABLE, and I have a row B from TABLE how can I do something like value := B.A in plpgsql in Postgresql

miggy92
  • 70
  • 10
  • 1
    Please **[EDIT]** your question and add some [sample data](http://plaintexttools.github.io/plain-text-table/) and the expected output based on that data. [**Formatted text**](http://stackoverflow.com/help/formatting) please, [**no screen shots**](http://meta.stackoverflow.com/questions/285551/why-may-i-not-upload-images-of-code-on-so-when-asking-a-question/285557#285557). **[edit]** your question - do **not** post code or additional information in comments. –  Nov 27 '17 at 13:30

1 Answers1

1

You need dynamic SQL with EXECUTE to parameterize any identifiers. And pass the row value as data with the USING clause Like:

EXEXUTE format('SELECT $1.%I ', A)
USING B
INTO  value_variable; -- with matching data type!

Related:

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228