Re: proposal: function parse_ident - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: proposal: function parse_ident
Date
Msg-id CAFj8pRBfXOvCUQiLRzQyrH_khv2zbX1ic-6Y32Qr+Unmhpx8aA@mail.gmail.com
Whole thread
In response to Re: proposal: function parse_ident  (Peter Eisentraut <peter_e@gmx.net>)
Responses Re: proposal: function parse_ident
List pgsql-hackers


2015-09-16 2:41 GMT+02:00 Peter Eisentraut <peter_e@gmx.net>:
On 9/11/15 6:25 AM, Pavel Stehule wrote:
> new update of parse_ident function patch

How would you actually use this?

I know several people have spoken up that they could use this, but could
you provide a few actual practical examples?


I see two basic use cases

1. processing user input with little bit more comfort - the user doesn't need to separate schema and table

CREATE OR REPLACE FUNCTION createtable(tablename text)
RETURNS void AS $$
DECLARE names text[];
BEGIN
  names := parse_ident(tablename);
  IF array_length(names) > 2 || array_length(names) = 0 THEN
    RAISE EXCEPTION 'wrong identifier';
  END IF;
  IF names[2] IS NOT NULL THEN
     CREATE SCHEMA IF NOT EXISTS names[2];
  END IF;
  CREATE TABLE tablename;
END;
$$ LANGUAGE plpgsql;

2. parsing error messages or some automatic variables

Regards

Pavel

pgsql-hackers by date:

Previous
From: Jeff Janes
Date:
Subject: Re: [PATCH] Microvacuum for gist.
Next
From: Yugo Nagata
Date:
Subject: T_PrivGrantee is left in NodeTag