| 731 | } |
| 732 | |
| 733 | inline bool check_column_exists(const std::string& table_name, |
| 734 | const std::string& column_name, |
| 735 | const std::string& schema_name = "public") |
| 736 | { |
| 737 | std::string query = fmt::format("SELECT 1 FROM information_schema.columns WHERE " |
| 738 | "table_schema = '{}' AND table_name = '{}' AND column_name = '{}'", |
| 739 | schema_name, |
| 740 | table_name, |
| 741 | column_name); |
| 742 | bool pushed_snapshot = false; |
| 743 | if (!ActiveSnapshotSet()) { |
| 744 | PushActiveSnapshot(GetTransactionSnapshot()); |
| 745 | pushed_snapshot = true; |
| 746 | } |
| 747 | spi_connector connector; |
| 748 | bool exists = SPI_execute(query.c_str(), true, 0) == SPI_OK_SELECT && SPI_processed > 0; |
| 749 | if (pushed_snapshot) { |
| 750 | PopActiveSnapshot(); |
| 751 | } |
| 752 | return exists; |
| 753 | } |
| 754 | |
| 755 | } // namespace utils |
| 756 | |