I'm slowly learning more about PostgreSQL, as we are attempting to move to it from MSSQL Server.
In MSSQL I have the following code:
DECLARE ServiceabilityParameters
CURSOR FORWARD_ONLY READ_ONLY STATIC LOCAL FOR
SELECT WorkbookParameterType.ID,
WorkbookParameterType.Name,
WorkbookParameter.DefaultValue,
WorkbookParameter.CommandText
FROM WorkbookParameter
JOIN WorkbookParameterType ON WorkbookParameterType.ID = WorkbookParameter.WorkbookParameterTypeID
JOIN WorkbookParameterDirectionType ON WorkbookParameterDirectionType.ID = WorkbookParameter.WorkbookParameterDirectionTypeID
AND WorkbookParameterDirectionType.Writable = 1
WHERE WorkbookParameter.WorkbookID = @WorkbookID
OPEN ServiceabilityParameters
FETCH NEXT FROM ServiceabilityParameters INTO @WorkbookParameterTypeID, @WorkbookParameterTypeName, @WorkbookDefaultValue, @WorkbookCommandText
WHILE @@FETCH_STATUS = 0
BEGIN
DECLARE @ActualValue NVARCHAR(256) = NULL
IF @WorkbookCommandText IS NOT NULL
BEGIN
EXEC sp_executesql @statement = @WorkbookCommandText,
@params = N'@ApplicationContainerID INT, @Value NVARCHAR(256) OUTPUT',
@ApplicationContainerID = @ApplicationContainerID,
@Value = @ActualValue OUTPUT
END
IF @ActualValue IS NULL AND @WorkbookDefaultValue IS NOT NULL
BEGIN
SET @ActualValue = @WorkbookDefaultValue
END
INSERT @InputParameters (
ID, Name, Value
) VALUES (
@WorkbookParameterTypeID, @WorkbookParameterTypeName, @ActualValue
)
FETCH NEXT FROM ServiceabilityParameters INTO @WorkbookParameterTypeID, @WorkbookParameterTypeName, @WorkbookDefaultValue, @WorkbookCommandText
END
CLOSE ServiceabilityParameters
DEALLOCATE ServiceabilityParameters
I'm trying to work out how to do the sp_executesql part in a PostgreSQL function. I believe that I can do the rest, but most of the examples that I have found show a simple select with maybe a few variables, whereas I need to execute another function, with parameters, where the function name is text in a table.
Many Thanks.