Text value within composite function result not quoted

Started by Guyren Howealmost 9 years ago5 messagesgeneral
Jump to latest
#1Guyren Howe
guyren@gmail.com

Define a couple of types:

CREATE TYPE request_in AS
(
path text[],
args jsonb,
server text,
port smallint,
headers jsonb,
body bytea,
type_requested text[]
);

CREATE TYPE request_out AS
(
status smallint,
headers jsonb,
body text
);

and a function:

CREATE OR REPLACE FUNCTION request(
req request_in)
RETURNS "request_out"
LANGUAGE 'plv8'
COST 100.0
VOLATILE
AS $function$
return {'status': 200, 'headers': {}, 'body': "<body>Works!</body>"}
$function$;

call the function:

SELECT request(
(
'{}',
'{}'::jsonb,
'',
8080,
'{}'::jsonb,
''::bytea,
'{}')::request_in
)

get this result:

(200,{},<body>Works!</body>)

This is the textual representation of the result I get in psql and Ruby. Note that the textual final value is not quoted.

I imagine I can work out a way to deal with this, but this is not the most felicitous way of representing a text value that I can imagine.

Note that if I add a single space after “Works!”, I get quotes around the string.

This is 9.6.2 on MacOS.

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Guyren Howe (#1)
Re: Text value within composite function result not quoted

Guyren Howe <guyren@gmail.com> writes:

... get this result:
(200,{},<body>Works!</body>)
This is the textual representation of the result I get in psql and Ruby. Note that the textual final value is not quoted.
I imagine I can work out a way to deal with this, but this is not the most felicitous way of representing a text value that I can imagine.
Note that if I add a single space after “Works!”, I get quotes around the string.

As per spec:

https://www.postgresql.org/docs/current/static/arrays.html#ARRAYS-IO

regards, tom lane

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#3Guyren Howe
guyren@gmail.com
In reply to: Tom Lane (#2)
Re: Text value within composite function result not quoted

On May 15, 2017, at 21:36 , Tom Lane <tgl@sss.pgh.pa.us> wrote:

... get this result:
(200,{},<body>Works!</body>)
This is the textual representation of the result I get in psql and Ruby. Note that the textual final value is not quoted.
I imagine I can work out a way to deal with this, but this is not the most felicitous way of representing a text value that I can imagine.
Note that if I add a single space after “Works!”, I get quotes around the string.

As per spec:

https://www.postgresql.org/docs/current/static/arrays.html#ARRAYS-IO <https://www.postgresql.org/docs/current/static/arrays.html#ARRAYS-IO&gt;

Thanks. This is… inconvenient. I see nothing about an option to force quoting of strings. Is there no such option? If not, I suggest that it would be a useful addition.

#4David G. Johnston
david.g.johnston@gmail.com
In reply to: Tom Lane (#2)
Re: Text value within composite function result not quoted

On Monday, May 15, 2017, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Guyren Howe <guyren@gmail.com <javascript:;>> writes:

... get this result:
(200,{},<body>Works!</body>)
This is the textual representation of the result I get in psql and Ruby.

Note that the textual final value is not quoted.

I imagine I can work out a way to deal with this, but this is not the

most felicitous way of representing a text value that I can imagine.

Note that if I add a single space after “Works!”, I get quotes around

the string.

As per spec:

https://www.postgresql.org/docs/current/static/arrays.html#ARRAYS-IO

Right idea (same output rules), wrong link. The output is a composite, not
an array.

https://www.postgresql.org/docs/current/static/rowtypes.html#ROWTYPES-IO-SYNTAX

David J.

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Guyren Howe (#3)
Re: Text value within composite function result not quoted

Guyren Howe <guyren@gmail.com> writes:

Thanks. This is… inconvenient. I see nothing about an option to force quoting of strings. Is there no such option? If not, I suggest that it would be a useful addition.

Force-quoting the elements would not move the goalposts all that much
concerning parse-ability of composite (or array) output. If you're
complaining about that, I strongly suspect your code also fails to cope
with embedded quotes, nested structures, and/or nulls.

You might consider expanding the query's output so that the fields are
delivered separately.

regards, tom lane

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general