EnterpriseDB / mysql_fdw

PostgreSQL foreign data wrapper for MySQL
Other
530 stars 162 forks source link

make column name mapping #123

Open eriendel opened 7 years ago

eriendel commented 7 years ago

it would be great if we could set different postgres column names. postgres_fdw has such option as column_name to set column name to map from

dland commented 6 years ago

It would appear that this part of the interface is not (yet) implemented. I tried to write

CREATE FOREIGN TABLE a (
  b text OPTIONS (column_name 'c')
);

and received

ERROR:  invalid option "column_name"
HINT:  Valid options in this context are: <none>

The use case is actually quite simple. I'm working with a legacy database that has lots of '0000-00-00 00:00:00' date time values, and you can't always cast to text to work around it. So what I really wanted to do was to have something like:

CREATE FOREIGN TABLE person (
  id integer,
  birthday date OPTIONS (column_name 'c')
  birthday_text text OPTIONS (column_name 'birthday')
);

Which would at least allow me to view bogus dates even if I can't do anything with them. (Not even sure if the foreign cast to text would even work, but I can't think of anything else to try).