0
votes

Can we use SQL to find out which keywords only mean something to Postgres inside a DO block or a PL/pgSQL function? And if not, can somebody perhaps tell me whether my list is complete or if there are words that shouldn't be on this list:

continue, exit, foreach, loop, return, return next, return query, slice, while, alias, begin, constant, declare, exception, execute, get (stacked) diagnostics, perform, raise, message, detail, hint, errcode, debug, log, info, notice, warning, found, sqlerrm, sqlstate, new, old, tg_name, tg_when, tg_level, tg_op, tg_relid, tg_relname, tg_table_name, tg_table_schema, tg_nargs, tg_argv, tg_event, tg_tag

1
You can check your list again the list of reserved keywords.JGH
How is that list helping here? foreach for example can only be used in a function or do block and isn't on that list at all.user1602492
And continuecan also only be used in a function or do block and is on the list.user1602492
So if it is on the list of reserved keywords, like for, it means it shouldn't be in your listJGH
Do you have an example where Postgres uses for outside a function or do block?user1602492

1 Answers

0
votes

You can find the list in src/pl/plpgsql/src/pl_scanner.c:

Reserved keywords:

ALL
BEGIN
BY
CASE
DECLARE
ELSE
END
EXECUTE
FOR
FOREACH
FROM
IF
IN
INTO
LOOP
NOT
NULL
OR
STRICT
THEN
TO
USING
WHEN
WHILE

“Non-reserved” keywords:

ABSOLUTE
ALIAS
ARRAY
ASSERT
BACKWARD
CLOSE
COLLATE
COLUMN
COLUMN_NAME
CONSTANT
CONSTRAINT
CONSTRAINT_NAME
CONTINUE
CURRENT
CURSOR
DATATYPE
DEBUG
DEFAULT
DETAIL
DIAGNOSTICS
DUMP
ELSEIF
ELSIF
ERRCODE
ERROR
EXCEPTION
EXIT
FETCH
FIRST
FORWARD
GET
HINT
IMPORT
INFO
INSERT
IS
LAST
LOG
MESSAGE
MESSAGE_TEXT
MOVE
NEXT
NO
NOTICE
OPEN
OPTION
PERFORM
PG_CONTEXT
PG_DATATYPE_NAME
PG_EXCEPTION_CONTEXT
PG_EXCEPTION_DETAIL
PG_EXCEPTION_HINT
PRINT_STRICT_PARAMS
PRIOR
QUERY
RAISE
RELATIVE
RESULT_OID
RETURN
RETURNED_SQLSTATE
REVERSE
ROW_COUNT
ROWTYPE
SCHEMA
SCHEMA_NAME
SCROLL
SLICE
SQLSTATE
STACKED
TABLE
TABLE_NAME
TYPE
USE_COLUMN
USE_VARIABLE
VARIABLE_CONFLICT
WARNING

Special variables like TG_RELID or FOUND are not keywords, even though they play a special role in PL/pgSQL.