Additional accessors via the Extension API ?

From: Markur Sens <markursens(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Additional accessors via the Extension API ?
Date: 2022-02-20 06:07:20
Message-ID: 6D4DE1F2-70C9-4BC4-92FD-0699BE0F8952@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Suppose I have defined an additional type in a PG extension.

Is it possible to add custom accessors to that type -much like jsonb does- but use an API/hook without touching the core PG grammar & parser?

Hypothetical Examples:

Assuming I have a TextFile type I’d like to implement syntax like:

(‘/home/me/a.txt’::TextFile).firstline
(‘/home/me/a.txt’::TextFile).lastline
(‘/home/me/a.txt’::TextFile).countlines()
(‘/home/me/a.txt’::TextFile).size()
(‘/home/me/a.txt’::TextFile).datemodified()

The only relevant patch I could find is [1] but it’s a dead-end

[1] https://www.postgresql.org/message-id/20210501072458.adqjoaqnmhg4l34l%40nol

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Karsten Hilbert 2022-02-20 09:23:27 Aw: Additional accessors via the Extension API ?
Previous Message Tom Lane 2022-02-19 19:34:58 Re: Strange results when casting string to double