* Execute given SQL string without SPI or a libpq session. */
| 1836 | * Execute given SQL string without SPI or a libpq session. |
| 1837 | */ |
| 1838 | static void |
| 1839 | ExecuteSqlString(const char *sql) |
| 1840 | { |
| 1841 | List *raw_parsetree_list; |
| 1842 | ListCell *lc1; |
| 1843 | bool isTopLevel; |
| 1844 | int commands_remaining; |
| 1845 | MemoryContext parsecontext; |
| 1846 | MemoryContext oldcontext; |
| 1847 | |
| 1848 | /* |
| 1849 | * Parse the SQL string into a list of raw parse trees. |
| 1850 | * |
| 1851 | * Because we allow statements that perform internal transaction control, |
| 1852 | * we can't do this in TopTransactionContext; the parse trees might get |
| 1853 | * blown away before we're done executing them. |
| 1854 | */ |
| 1855 | parsecontext = AllocSetContextCreate(TopMemoryContext, |
| 1856 | "pg_cron parse/plan", |
| 1857 | ALLOCSET_DEFAULT_MINSIZE, |
| 1858 | ALLOCSET_DEFAULT_INITSIZE, |
| 1859 | ALLOCSET_DEFAULT_MAXSIZE); |
| 1860 | oldcontext = MemoryContextSwitchTo(parsecontext); |
| 1861 | raw_parsetree_list = pg_parse_query(sql); |
| 1862 | commands_remaining = list_length(raw_parsetree_list); |
| 1863 | isTopLevel = commands_remaining == 1; |
| 1864 | MemoryContextSwitchTo(oldcontext); |
| 1865 | |
| 1866 | /* |
| 1867 | * Do parse analysis, rule rewrite, planning, and execution for each raw |
| 1868 | * parsetree. We must fully execute each query before beginning parse |
| 1869 | * analysis on the next one, since there may be interdependencies. |
| 1870 | */ |
| 1871 | foreach(lc1, raw_parsetree_list) |
| 1872 | { |
| 1873 | RawStmt *parsetree = (RawStmt *) lfirst(lc1); |
| 1874 | CommandTag commandTag; |
| 1875 | QueryCompletion qc; |
| 1876 | List *querytree_list; |
| 1877 | List *plantree_list; |
| 1878 | bool snapshot_set = false; |
| 1879 | Portal portal; |
| 1880 | DestReceiver *receiver; |
| 1881 | int16 format = 1; |
| 1882 | |
| 1883 | /* |
| 1884 | * We don't allow transaction-control commands like COMMIT and ABORT |
| 1885 | * here. The entire SQL statement is executed as a single transaction |
| 1886 | * which commits if no errors are encountered. |
| 1887 | */ |
| 1888 | if (IsA(parsetree, TransactionStmt)) |
| 1889 | ereport(ERROR, |
| 1890 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 1891 | errmsg("transaction control statements are not allowed in pg_cron"))); |
| 1892 | |
| 1893 | /* |
| 1894 | * Get the command name for use in status display (it also becomes the |
| 1895 | * default completion tag, down inside PortalRun). Set ps_status and |
no test coverage detected