CREATE_TEXT_SEARCH_TEMPLATE(7pg14)
β¨ CREATE_TEXT_SEARCH_TEMPLATE π
okay so real talk, this is the CREATE_TEXT_SEARCH_TEMPLATE page from the PostgreSQL 14.24 docs, and it's genuinely such a niche little corner of Postgres but it's so interesting once you get it. bestie, let's go π«Ά
π NAME π
CREATE_TEXT_SEARCH_TEMPLATE β define a new text search template. that's it, that's the whole name section, she's concise π
πΈ SYNOPSIS πΈ
CREATE TEXT SEARCH TEMPLATE name (
[ INIT = init_function , ]
LEXIZE = lexize_function
)
like, literally copy-paste that shape and you're golden β¨
π¦ DESCRIPTION π¦
okay so CREATE TEXT SEARCH TEMPLATE creates a new text search template. and what is a text search template, you ask? it's the thing that defines the functions that implement text search dictionaries. cute, right?
here's the tea though: a template is not useful by itself π it's giving scaffolding energy. you have to instantiate it as a dictionary before you can actually use it. and the dictionary typically specifies the parameters that get handed to the template functions. so the template is like the vibe, and the dictionary is the actual main character π
if you give a schema name, the text search template gets created in that specified schema. otherwise? it lands in the current schema. default behavior, no cap π
β οΈ superuser only, bestie β you must be a superuser to use CREATE TEXT SEARCH TEMPLATE. and no, this isn't just gatekeeping for fun: the restriction exists because an erroneous text search template definition could confuse or even crash the server π like, actually crash it. so yeah, the lock is there for a reason.
and here's why templates are separated from dictionaries in the first place: a template encapsulates the "unsafe" aspects of defining a dictionary. meanwhile, the parameters you can set when defining a dictionary are safe for unprivileged users to set β which means creating a dictionary doesn't need to be a privileged operation at all π«Ά iconic design choice, honestly.
for even more info, refer to Chapter 12 π
π PARAMETERS π
nameβ the name of the text search template to be created. and yes, it can be schema-qualified, so go off with yourmyschema.mytemplateβ¨init_functionβ the name of the init function for the template π§lexize_functionβ the name of the lexize function for the template π
okay, a couple of notes on these function names, because they matter:
- the function names can be schema-qualified if necessary.
- argument types are not given, because the argument list for each type of function is predetermined. so don't come in here trying to annotate your types, it's not that kind of party π
- the
lexizefunction is required π₯ but theinitfunction is optional. soLEXIZEis the non-negotiable one, periodt. - and the arguments can appear in any order β not only the one shown in the synopsis above. so you do you, bestie β
π« COMPATIBILITY π«
there is no CREATE TEXT SEARCH TEMPLATE statement in the SQL standard. so if some other database is acting like this is standard behavior... it's not. we're built different π
π SEE ALSO π
ALTER TEXT SEARCH TEMPLATE(ALTER_TEXT_SEARCH_TEMPLATE(7))DROP TEXT SEARCH TEMPLATE(DROP_TEXT_SEARCH_TEMPLATE(7))
go read those next, they're the natural sequels π
alright bestie, that's the whole page β shoutout to the PostgreSQL 14.24 docs, dated 2026, for this absolute gem of a manual page. now go make some templates (as a superuser, obviously) ππ
π¦ where this page comes from
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms