1

We are moving our database from Advantage Database to PostgreSQL. One of the common patterns we use is something like:

TRY DROP TABLE #TemporaryTable; CATCH ALL END TRY;
SELECT Field1, Field2
INTO #TemporaryTable
FROM MainTable
WHERE Type=1;

CREATE INDEX FirstIndex ON #TemporaryTable (Field2);

We set a TAdsQuery down and issue ExecSQL. Then we set a TAdsTable down and open the #TemporaryTable. We can then set the IndexName to "FirstIndex". You can do this at design time if you like and all indexes show under the IndexName drop down.

When researching this pattern under PostgreSQL we found that the indexes are not available under the TFDTable. Here's the pattern we've implemented so far.

With TFDQuery execute:

DROP TABLE IF EXISTS TemporaryTable;

SELECT Field1, Field2
INTO TEMP TemporaryTable
FROM MainTable
WHERE Type=1;

CREATE INDEX FirstIndex ON TemporaryTable (Field2);

We can see the indexes do exist if we issue this SQL:

SELECT
    indexname,
    indexdef
FROM
    pg_indexes

But they are not available to the TFDTable to set at design time or at run time.

We can of course use IndexFieldNames, but other parts of our UI implement themselves based on a pre-defined list of indexes that were specifically created.

1
  • Firedac caches metadata and catalog information with the connection. See: RefreshMetadataCache for one way to refresh it. There are other options that may work better with your existing code / usage.
    – Brian
    Sep 27 at 17:39

1 Answer 1

1

After digging I found that PostgreSQL puts your temporary tables under a unique schema name for the collection.

I was able to write a helper function that, given an TFDConnection object, will return the current unique schema for the connection:

select nspname from pg_namespace where oid = pg_my_temp_schema();

As long as I assign the result of this function to the SchemaName property of the TFDTable, it can hook everything else up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.