public inbox for [email protected]
help / color / mirror / Atom feedUser defined type without single quotes
3+ messages / 2 participants
[nested] [flat]
* User defined type without single quotes
@ 2013-04-04 22:50 Rodrigo Barboza <[email protected]>
0 siblings, 1 reply; 3+ messages in thread
From: Rodrigo Barboza @ 2013-04-04 22:50 UTC (permalink / raw)
To: pgsql-docs
Hello.
I defined a new type to represent an unsigned int, but when I try do run a
query it complains because it is not quoted and casted to my type.
Suppose I have a table:
-- my_uint32 is my new type
CREATE TABLE test (a my_uin32);
If I try to run this insert, postgres complain about the type:
INSERT INTO teste (a) VALUES (10);
But this one works:
NSERT INTO teste (a) VALUES ('10'::my_uint);
Is there a way to avoid the single quotes?
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: User defined type without single quotes
@ 2013-04-13 13:06 Peter Eisentraut <[email protected]>
parent: Rodrigo Barboza <[email protected]>
0 siblings, 1 reply; 3+ messages in thread
From: Peter Eisentraut @ 2013-04-13 13:06 UTC (permalink / raw)
To: Rodrigo Barboza <[email protected]>; +Cc: pgsql-docs
On Thu, 2013-04-04 at 19:50 -0300, Rodrigo Barboza wrote:
> -- my_uint32 is my new type
> CREATE TABLE test (a my_uin32);
>
> If I try to run this insert, postgres complain about the type:
> INSERT INTO teste (a) VALUES (10);
>
> But this one works:
> NSERT INTO teste (a) VALUES ('10'::my_uint);
>
> Is there a way to avoid the single quotes?
>
A constant like 10 is initially assigned one of the integer types (the
exact rules are in the documentation). In order to be able to store
that into a column of a custom type, you need to define a cast between
the integer type and your type with at least assignment context.
--
Sent via pgsql-docs mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-docs
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: User defined type without single quotes
@ 2013-04-13 17:23 Rodrigo Barboza <[email protected]>
parent: Peter Eisentraut <[email protected]>
0 siblings, 0 replies; 3+ messages in thread
From: Rodrigo Barboza @ 2013-04-13 17:23 UTC (permalink / raw)
To: Peter Eisentraut <[email protected]>; +Cc: pgsql-docs
Thank you, Peter!
On Sat, Apr 13, 2013 at 10:06 AM, Peter Eisentraut <[email protected]> wrote:
> On Thu, 2013-04-04 at 19:50 -0300, Rodrigo Barboza wrote:
> > -- my_uint32 is my new type
> > CREATE TABLE test (a my_uin32);
> >
> > If I try to run this insert, postgres complain about the type:
> > INSERT INTO teste (a) VALUES (10);
> >
> > But this one works:
> > NSERT INTO teste (a) VALUES ('10'::my_uint);
> >
> > Is there a way to avoid the single quotes?
> >
> A constant like 10 is initially assigned one of the integer types (the
> exact rules are in the documentation). In order to be able to store
> that into a column of a custom type, you need to define a cast between
> the integer type and your type with at least assignment context.
>
>
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2013-04-13 17:23 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-04-04 22:50 User defined type without single quotes Rodrigo Barboza <[email protected]>
2013-04-13 13:06 ` Peter Eisentraut <[email protected]>
2013-04-13 17:23 ` Rodrigo Barboza <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox