0

I am using postgresql and I have the following table

 Table "public.test"
 Column | Type | Modifiers 
--------+--------------------------+-----------
 name | text | 
 time | timestamp with time zone | 
 name | time 
-------+------------------------
 ticka | 2016年07月08日 21:22:58+00
(1 row)

When I do the command:

select substring(name from '.*') from test;

I get a result, but when I do it for the time column I get:

Error: LINE 1: select substring(time from '.*' ) from test;
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.

Why is this? How can I solve it?

András Váczi
31.8k13 gold badges103 silver badges152 bronze badges
asked Jul 18, 2018 at 7:16

1 Answer 1

1

Ok, because the function is called substring, I think it only works for the string data type but not for the timestamp data type

To solve this I use the regular expression on the timestamp by converting the timestamp into a text first using the to_char function and then I use the substring function as follows:

select substring(to_char(time,'YYYY-MM-DD HH:MM:SS') from '.*') from test;
Marco
3,7205 gold badges25 silver badges31 bronze badges
answered Jul 18, 2018 at 7:26
2
  • Please tick the tickmark on your answer, that is the indicator of solved issues, not the [solved] tag in the title. Commented Jul 18, 2018 at 8:17
  • haha, sorry for this, i thought that i have to added manually Commented Jul 18, 2018 at 9:44

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.